This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ProgBlog/app/helpers/password-hash.js

30 lines
647 B
JavaScript

'use strict';
const scrypt = require('scrypt');
module.exports = {
/**
* Hash a password with scrypt
*
* @param {string} str - the password to hash
* @return {Promise} - a promise returning the hash
*/
hash(str) {
return scrypt.kdf(str, {
N:16, // Number of rounds
r:8, // Block-size of hash
p:1, // Parallization
});
},
/**
* Verify a password hash matches
*
* @param {string} hash - the hash to check against
* @param {string} str - the password to check against the computed hash
* @return {Promise} - a promise returning a boolean
*/
verify(hash, str) {
return scrypt.verifyKdf(hash, str);
},
};