verifyPassword
The verifyPassword function compares a plain text password against a hashed password, either using bcrypt for hashed comparisons or directly comparing plain text passwords.
Works in: Node.js, React JS, HTML5
| Parameter | Type | Default | Description |
|---|---|---|---|
stringPassword | string | undefined | The plain text password to verify. |
hashedPassword | string | undefined | The hashed password to compare against. |
isHashed | boolean | false | Indicates whether the provided password is already hashed. Default is false. |
Usage
Example: Verify Plain Text Password
const plainTextPassword = 'Password123';
const hashedPassword = '$2a$10$SJVY.s8OD3S1D3HJh3n3MeI8yzUmJm0bO5L2R3Z78b8MWg8L4NLqG';
nfsfu234FormValidation.verifyPassword(plainTextPassword, hashedPassword)
.then(isMatch => {
console.log("Passwords Match: ", isMatch); // true or false
})
.catch(error => {
console.error("Error verifying password: ", error);
});Example: Verify Hashed Password
const plainTextPassword = 'Password123';
const hashedPassword = '$2a$10$SJVY.s8OD3S1D3HJh3n3MeI8yzUmJm0bO5L2R3Z78b8MWg8L4NLqG';
nfsfu234FormValidation.verifyPassword(plainTextPassword, hashedPassword, true)
.then(isMatch => {
console.log("Passwords Match: ", isMatch); // true or false
})
.catch(error => {
console.error("Error verifying password: ", error);
});Last updated on