Table of Contents

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

password string

The 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

password string

The plain text password to verify.

hash string

The BCrypt password hash to verify against.

Returns

bool

true if the password matches the hash; otherwise, false.

Remarks

BCrypt automatically handles salt extraction and comparison, making this operation secure against timing attacks.