How to storage a password in database #OWASP #wecommit100xshare
IProper password storage is critical for ensuring the security of user accounts. OWASP provides a comprehensive set of guidelines to help developers implement secure password storage mechanisms. Here is a detailed cheat sheet based on OWASP recommendations.
1.Use Strong Hashing Algorithms
Recommended Algorithms: Use modern, cryptographic hash functions designed specifically for password hashing, such as Argon2, bcrypt, or PBKDF2.
Argon2: Winner of the Password Hashing Competition (PHC) and considered the most secure. It has configurable memory, time, and parallelism parameters.
bcrypt: Incorporates a salt to protect against rainbow table attacks and adapts over time with a configurable cost factor.
PBKDF2: Uses a salt and iterates the hashing process to make brute-force attacks more difficult.
2. Use Salts
Purpose: Salts prevent attackers from using precomputed hashes (rainbow tables) to crack passwords.
Implementation: Generate a unique, random salt for each user password.
Length: Salts should be at least 16 bytes long.
Storage: Store the salt along with the hashed password.
3. Use Pepper
Purpose: A pepper is a secret value added to the password before hashing, adding an extra layer of security.
Implementation: The pepper should be stored securely and separately from the hashed passwords, such as in application code or a secure environment variable.
4. Apply Adequate Work Factor
Purpose: The work factor controls the computational cost of hashing, making it more difficult for attackers to crack passwords via brute force.
Configuration:
Argon2: Adjust memory cost, time cost, and parallelism to balance security and performance.
bcrypt: Increase the cost factor as hardware capabilities improve.
PBKDF2: Increase the number of iterations over time.
5. Use Secure Password Policies
Purpose: Strong password policies help ensure that users create passwords that are difficult to guess or crack.
Recommendations:
Length: Minimum of 8 characters; longer passwords are encouraged.
Complexity: Encourage the use of uppercase letters, lowercase letters, numbers, and special characters.
领英推荐
Password Managers: Encourage users to use password managers to create and store complex passwords.
6. Enforce Rate Limiting and Account Lockout
Rate Limiting: Implement rate limiting to slow down brute-force attacks.
Account Lockout: Temporarily lock accounts after a certain number of failed login attempts. Ensure that legitimate users can regain access securely.
7. Secure Transmission and Storage
Transmission: Always use HTTPS to encrypt passwords in transit.
Storage: Store only hashed and salted passwords. Never store plaintext passwords.
8. Regularly Update Security Practices
Algorithm Updates: Stay informed about the latest developments in cryptographic algorithms and update your password hashing mechanisms accordingly.
Security Audits: Conduct regular security audits and penetration tests to identify and address vulnerabilities.
One Way Hashing
How to storage a password in database
I updated my post at: 2024-07-26 for recommendation from "Paul Moore"
Storing passwords securely in a database is crucial for protecting user data. Using a combination of hashing, salting, and key stretching algorithms such as bcrypt is recommended. Peppers can also add an additional layer of security when used correctly. Here's an example of how to store a password using bcrypt and HMAC in JavaScript.
Steps for Secure Password Storage
Example Implementation in JavaScript
recommendation for tools online: https://argon2.online/
Salts used to provide protection against rainbow tables, back when they were applicable... but it's no longer 2001. Salts do not strengthen a password. They are intended to transform a deterministic process into something random; by ensuring no two credentials provide the same hash. They should be globally unique & cryptographically random. Peppers should not be used in the manner you're describing. To use them safely, use a HMAC inner wrapper inside bCrypt or similar. For example, bCrypt(HMAC_SHA512("password", "pepper")).