8 Tweets 2 reads Dec 24, 2022
1/ How to store passwords safely in the database and how to validate a password? Let’s take a look.
𝐓𝐑𝐒𝐧𝐠𝐬 ππŽπ“ 𝐭𝐨 𝐝𝐨
πŸ”Ή Storing passwords in plain text is not a good idea because anyone with internal access can see them.
2/ πŸ”Ή Storing password hashes directly is not sufficient because it is pruned to precomputation attacks, such as rainbow tables.
πŸ”Ή To mitigate precomputation attacks, we salt the passwords.
3/ π–π‘πšπ­ 𝐒𝐬 𝐬𝐚π₯𝐭?
According to OWASP guidelines, β€œa salt is a unique, randomly generated string that is added to each password as part of the hashing process”.
4/ 𝐇𝐨𝐰 𝐭𝐨 𝐬𝐭𝐨𝐫𝐞 𝐚 𝐩𝐚𝐬𝐬𝐰𝐨𝐫𝐝 𝐚𝐧𝐝 𝐬𝐚π₯𝐭?
1️⃣ A salt is not meant to be secret and it can be stored in plain text in the database. It is used to ensure the hash result is unique to each password.
5/ 2️⃣ The password can be stored in the database using the following format: 𝘩𝘒𝘴𝘩( 𝘱𝘒𝘴𝘴𝘸𝘰𝘳π˜₯ + 𝘴𝘒𝘭𝘡).
𝐇𝐨𝐰 𝐭𝐨 𝐯𝐚π₯𝐒𝐝𝐚𝐭𝐞 𝐚 𝐩𝐚𝐬𝐬𝐰𝐨𝐫𝐝?
To validate a password, it can go through the following process:
1️⃣ A client enters the password.
6/ 2️⃣ The system fetches the corresponding salt from the database.
3️⃣ The system appends the salt to the password and hashes it. Let’s call the hashed value H1.
4️⃣ The system compares H1 and H2 (H2 is the hash stored in the database). If they are the same, the password is valid
7/ Over to you: what other mechanisms can we use to ensure password safety?
8/ If you found this thread helpful, follow me
@alexxubyte for more.
Retweet the first tweet to help more people to learn system design.

Loading suggestions...