The main problem with storing passwords is how to do it securely. If passwords are stored in plaintext, anyone with root privilege can access them. If passwords are encrypted, the encryption key can be compromised. However, it is not necessary to be able to decrypt a stored password value, which opens up the possibility for more secure solutions.
To securely store passwords, systems often use hashed passwords, which are created by applying a one-way function, such as a cryptographic hash function, to the password. This produces a fixed-size output string, known as a hashed value or message digest, that cannot be reversed to reveal the original password. Examples of hash functions include MD4, MD5, SHA-1, SHA-2, and others. The OS then only needs to store the hashed values. When a user enters a password, the OS hashes that password and compares it to the hashed value it already stores.