Passwords are stored on the computer as hashes, those are only one-way. You can hash a value, but you can't retrieve the value back.
The authentication works like this :
- Create password, hash it, then store it.
- The user tries to login, the password he puts in gets hashed, and is then compared to the hash stored on the computer.
Popular hashing algorithms are:
Sha-2, MD5, NTLMv2 (windows 7 and 8 use this one)
Also, an addition:
Usually you hash something multiple times, for example 1000 times, this way it is longer to compute, and brute force attacks (trying each possible password, and comparing it with your hash) take longer.
You also use a salt, which is stored unencrypted next to the password, which is just some high number, and differs for each password. This way when there are two similair passwords, the attacker won't notice it.