Papotitu Papotitu - 25 days ago 7
Node.js Question

Implement Security::Hash from Cakephp in nodejs

so I have a login method in CakePHP using

Security::hash($password, NULL, true)
, and I'd like to implement this in NodeJS.
I tried this:

var sha1 = function(password, salt){
password = salt + password;
var hash = crypto.createHmac('sha1', ''); /** Hashing algorithm sha1 */
hash.update(password);
var value = hash.digest('hex');
console.log(value);
return {
salt:salt,
passwordHash:value
};
};


but the result hash is different from what Cake gave me. What am I doing wrong ?

Answer

Found it !

    var hash_sha1 = function(password, salt){
    password = salt + password;
    var hash = crypto.createHash('sha1'); /** Hashing algorithm sha1 */
    hash.update(password);
    var value = hash.digest('hex');
    return value;
};

Made a little gist about it : https://gist.github.com/Wats0ns/bb6210d4bfb4e0ce9d8db41750661363