Overview
AuthService uses PBKDF2-SHA512 with 600,000 iterations for password hashing, following NIST SP 800-132 recommendations and OWASP 2024 guidelines for password storage.PBKDF2 (Password-Based Key Derivation Function 2) is a key derivation function that applies a pseudorandom function to the input password along with a salt value and repeats the process many times to produce a derived key.
Implementation Details
Hash Parameters
The password service uses the following cryptographic parameters:Services/PasswordService.cs
| Parameter | Value | Rationale |
|---|---|---|
| Salt Size | 32 bytes (256 bits) | Ensures each password hash is unique, prevents rainbow table attacks |
| Hash Size | 64 bytes (512 bits) | Matches SHA-512 output size for maximum security |
| Iterations | 600,000 | OWASP 2024 recommendation for PBKDF2-HMAC-SHA512, balances security and performance |
| Algorithm | SHA-512 | More secure than SHA-256, widely supported in .NET |
Hashing Process
When a user registers or changes their password, the service generates a cryptographically secure hash:Services/PasswordService.cs
- Iteration count - Allows for future upgrades (e.g., increasing from 600k to 1M)
- Salt (Base64) - The random salt used for this specific password
- Hash (Base64) - The derived key from PBKDF2
Password Verification
During login, the service verifies passwords using constant-time comparison:Services/PasswordService.cs
Security Rationale
Why PBKDF2 Over BCrypt?
While BCrypt is a popular choice, this implementation uses PBKDF2 for several reasons:Explicit Parameter Control
Explicit Parameter Control
PBKDF2 provides fine-grained control over iteration count, salt size, hash size, and underlying algorithm. This allows tuning for specific security requirements without library limitations.
NIST Compliance
NIST Compliance
PBKDF2 is explicitly recommended by NIST SP 800-132 for password-based key derivation. Organizations with compliance requirements often mandate NIST-approved algorithms.
Native .NET Support
Native .NET Support
PBKDF2 via
Rfc2898DeriveBytes is built into .NET Core with optimized implementations. BCrypt requires third-party libraries which add dependencies and potential supply chain risks.Future-Proof Design
Future-Proof Design
The hash format includes the iteration count, making it easy to increase security parameters over time as computing power increases. When a user logs in with an old hash, the system can detect it and automatically rehash with updated parameters.
Constant-Time Comparison
The verification process usesCryptographicOperations.FixedTimeEquals() to prevent timing attacks:
Timing attacks exploit the fact that comparison operations can take different amounts of time depending on where the first difference occurs. An attacker can use this timing information to gradually guess the correct hash byte-by-byte.
Integration Example
The password service is injected and used during registration:Services/AuthService.cs
Services/AuthService.cs
Standards Compliance
NIST SP 800-132
The implementation follows NIST Special Publication 800-132 recommendations:- Uses an approved pseudorandom function (HMAC-SHA512)
- Minimum iteration count of 10,000 (we use 600,000)
- Salt length of at least 128 bits (we use 256 bits)
- Output length matches the underlying hash function
OWASP 2024 Guidelines
Complies with OWASP Password Storage Cheat Sheet:- 600,000 iterations for PBKDF2-HMAC-SHA512 (2024 recommendation)
- Cryptographically random salt per password
- Salt stored with the hash
- Constant-time comparison for verification
OWASP iteration count recommendations increase over time as computing power improves. The 2024 guideline is 600,000 iterations for PBKDF2-HMAC-SHA512, up from 210,000 in 2023.
Performance Considerations
With 600,000 iterations, password hashing is intentionally slow:- Registration: ~200-300ms per password hash
- Login: ~200-300ms per password verification
Best Practices
- Never log passwords - The implementation never logs the plaintext password, only email and events
- Use HTTPS - Always transmit passwords over encrypted connections
- Validate input - Enforce password complexity requirements before hashing
- Rate limiting - See Account Lockout for failed attempt protection
- Regular updates - Monitor OWASP guidelines and update iteration counts as recommended
Related Topics
- Account Lockout - Failed login attempt protection
- Token Validation - JWT security mechanisms
- Authentication Flow - Complete authentication process