Class PasswordHasher
- Namespace
- Builvero.Infrastructure.Services
- Assembly
- Builvero.Infrastructure.dll
Implementation of IPasswordHasher using BCrypt for secure password hashing and verification.
public class PasswordHasher : IPasswordHasher
- Inheritance
-
PasswordHasher
- Implements
- Inherited Members
Remarks
This implementation uses BCrypt with a work factor of 12, which provides a good balance between security and performance. The work factor determines the computational cost of hashing, making brute-force attacks more expensive.
Methods
HashPassword(string)
Hashes a password using BCrypt with a work factor of 12.
public string HashPassword(string password)
Parameters
passwordstringThe plain text password to hash.
Returns
- string
A BCrypt hashed password string that can be safely stored in the database.
Remarks
The work factor of 12 means 2^12 (4,096) iterations, which provides strong security while maintaining acceptable performance for authentication operations.
VerifyPassword(string, string)
Verifies a password against a BCrypt hash.
public bool VerifyPassword(string password, string hash)
Parameters
passwordstringThe plain text password to verify.
hashstringThe BCrypt password hash to verify against.
Returns
- bool
trueif the password matches the hash; otherwise,false.
Remarks
BCrypt automatically handles salt extraction and comparison, making this operation secure against timing attacks.