node-password-hash
node-password-hash copied to clipboard
Not returning True (isHashed)
var passwordHash = require('password-hash');
var hashedPassword = 'sha1$3I7HRwy7$cbfdac6008f9cab4083784cbd1874f76618d2a97';
console.log(passwordHash.isHashed('password123')); // false
console.log(passwordHash.isHashed(hashedPassword)); // true
passwordHash.isHashed() will always return False?
yes, the code is splitting the password with $ and checking for four segments where as the hashed password is having only 3
so, try
var passwordHash = require('password-hash');
passwordHash.isHashed = function(password) {
if (!password) return false;
return password.split('$').length === 3;
}
var hashedPassword = 'sha1$3I7HRwy7$cbfdac6008f9cab4083784cbd1874f76618d2a97';
console.log(passwordHash.isHashed('password123')); // false
console.log(passwordHash.isHashed(hashedPassword)); // true