Password Encrypt
Decrypt Password
The decrypt
module provides a function for comparing a plaintext password with its hashed counterpart. This utility ensures password integrity and verifies whether a provided plaintext password matches its hashed representation.
Features
- Password Verification: Compare a plaintext password with its hashed counterpart to verify authenticity.
- SHA-256 Hashing: Utilizes the SHA-256 hashing algorithm for secure password comparison.
- Error Handling: Throws descriptive errors when input validation fails, providing detailed feedback for improved debugging.
- Easy Integration: Seamlessly integrate the
comparePasswords
function into your Node.js applications to verify passwords effortlessly.
Usage
const { decrypt } = require('apiutils.js');
const plainTextPassword = 'myPassword123';
const hashedPassword = 'jrfiIvW0m6Nr/CXkMUwGc7QlOh6cS2bJg/ZmEl/HE=';
try {
const passwordMatch = decrypt(plainTextPassword, hashedPassword);
if (passwordMatch) {
console.log('Passwords match!');
} else {
console.log('Passwords do not match.');
}
} catch (error) {
console.error('Error:', error.message);
}
Parameters
plain_text
(string): The plaintext password to compare.hashedPassword
(string): The hashed password to compare against.
Return Value
- Returns
true
if the plaintext password matches the hashed password, otherwisefalse
.
Throws
- Throws an error if either the plaintext password or the hashed password is not provided or is not a string.