Introduction to Password Security
Password security is fundamental to application security. Despite advances in authentication methods like OAuth and biometrics, passwords remain the most common authentication mechanism. This guide covers modern best practices for password handling, storage, and validation.
Modern Password Requirements
Traditional password policies often create poor user experiences without improving security. Modern approaches focus on length and complexity rather than arbitrary character requirements.
Recommended Requirements
- Minimum length: 12 characters (preferably 16+)
- Maximum length: 128 characters (allow long passphrases)
- Character sets: Allow all Unicode characters
- No complexity rules: Don't require specific character types
- Common password checks: Check against known breached passwords
What to Avoid
- Password expiration policies (NIST no longer recommends)
- Maximum password age requirements
- Arbitrary complexity rules (must include number, symbol, etc.)
- Password hints that reveal the password
Password Hashing Algorithms
Choosing the right hashing algorithm is critical for password security. Here are the recommended algorithms in order of preference:
1. Argon2 (Recommended)
Winner of the Password Hashing Competition (PHC), Argon2 is memory-hard and resistant to GPU/ASIC attacks.
2. bcrypt
Well-established, battle-tested algorithm with built-in salt and adjustable work factor.
3. scrypt
Memory-hard algorithm designed to be resistant to hardware attacks.
Password Storage Strategies
Database Schema Design
Security Considerations
- Separate authentication database: Store password hashes separately from user data
- Encrypt at rest: Use database encryption for sensitive columns
- Audit logging: Log authentication attempts (success/failure)
- Rate limiting: Implement login attempt limits
Implementation Guidelines
Registration Flow
- Validate password meets requirements
- Check against known breached passwords (HaveIBeenPwned API)
- Generate cryptographically secure salt
- Hash password with appropriate algorithm
- Store hash and metadata in database
- Send confirmation email (if required)
Login Flow
- Retrieve user record by email/username
- Verify password hash matches
- Update last login timestamp
- Generate session token/JWT
- Set secure HTTP-only cookie
Common Password Security Vulnerabilities
1. Weak Hashing Algorithms
Avoid: MD5, SHA-1, SHA-256 (without proper key stretching)
These algorithms are too fast and vulnerable to brute force attacks.
2. Insufficient Work Factor
bcrypt with cost factor less than 12 or Argon2 with insufficient memory/time cost.
3. No Salt or Weak Salt
Using the same salt for all passwords or insufficiently random salt.
4. Password in Logs
Accidentally logging passwords in application logs or error messages.
Tools and Resources
DailyTools.uk Password Tool
Use our Password Generator Tool to create secure passwords and test password strength.
External Resources
- Have I Been Pwned Password API - Check passwords against known breaches
- OWASP Password Storage Cheat Sheet
- NIST Digital Identity Guidelines
Conclusion
Password security requires careful implementation of modern best practices. Focus on using strong hashing algorithms (Argon2, bcrypt), appropriate work factors, and comprehensive validation. Regularly audit your password handling code and stay updated with security recommendations from organizations like OWASP and NIST.
Remember that password security is just one component of a comprehensive authentication system. Consider implementing multi-factor authentication (MFA), monitoring for suspicious activity, and providing users with password managers to improve overall security.