node-password-hash icon indicating copy to clipboard operation
node-password-hash copied to clipboard

Not returning True (isHashed)

Open benkraw opened this issue 9 years ago • 1 comments

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?

benkraw avatar Aug 22 '16 18:08 benkraw

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

MContagious avatar Dec 05 '16 15:12 MContagious