I'm not going to give any example scripts, because there just isn't enough room for them and there are already heaps you can find in your preferred search engine. Also, it's relatively easy to code yourself if you know a scripting language (such as PHP) and SQL, and you know how it all fits together. So instead I'll explain the logic behind it, because it's pointless to copy and paste an example if you don't know for yourself what everything does.
User account data doesn't simply pop out of nowhere; it needs to be stored somewhere. This is where the database comes in. You can create a database to store account-related information, divided into smaller groups, or database tables. For instance, you may have one table store usernames and passwords, another for user profiles etc.
However, the database itself is useless if there's no data to store in the first place. This is where registration comes in; users come to a page where they are asked to give a username and password, along with any other tidbits you want to collect. You'll need to protect against malicious input by only accepting anything you know is clean, and you many also wish to keep spambots at bay by implementing a system whereby a user must confirm their registration by email. When the form is submitted, it is stored in the database, ready for access.
Finally, once the user has created an account, they'll need a way to access their data. To do this, there needs to be a way to verify that the data they want is in fact theirs. This process, logging in, is usually done on the home page, and requires a user to fill in their username and password. Once this is submitted, it is checked to make sure it's harmless, and is verified against the database information. If the submitted login data perfectly matches something in the database, it is accepted and the user is logged in, able to view and/or modify their data. Otherwise, the user is denied entry.
So in short: you create a database and tables to store data, make a registration page to collect it, and a login page to access it - storage, collection, access.