Securely compares a plaintext password against a bcrypt hash to verify user
credentials during authentication. Uses bcrypt's built-in comparison function
which handles timing-safe comparison to prevent timing attacks.
This function is essential for user login operations where stored password
hashes need to be verified against user-provided plaintext passwords.
The comparison is cryptographically secure and resistant to timing attacks.
Parameters
password: string
Plaintext password to verify
hash: string
Bcrypt hash to compare against
Returns Promise<boolean>
Promise resolving to true if password matches hash, false otherwise
Example
// Verify user password during login constisValidPassword = awaitcomparePassword( 'userPassword123!', '$2b$12$...'// stored hash from database );
Compare plaintext password with bcrypt hash
Securely compares a plaintext password against a bcrypt hash to verify user credentials during authentication. Uses bcrypt's built-in comparison function which handles timing-safe comparison to prevent timing attacks.
This function is essential for user login operations where stored password hashes need to be verified against user-provided plaintext passwords. The comparison is cryptographically secure and resistant to timing attacks.