2017-10-22 09:10:33 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-03 08:48:02 +08:00
|
|
|
const options = require('./options');
|
2017-10-15 11:31:44 +08:00
|
|
|
const scrypt = require('scrypt');
|
|
|
|
|
|
|
|
async function getVerificationHash(password) {
|
2017-11-03 08:48:02 +08:00
|
|
|
const salt = await options.getOption('password_verification_salt');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
|
|
|
return getScryptHash(password, salt);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getPasswordDerivedKey(password) {
|
2017-11-03 08:48:02 +08:00
|
|
|
const salt = await options.getOption('password_derived_key_salt');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
|
|
|
return getScryptHash(password, salt);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getScryptHash(password, salt) {
|
|
|
|
const hashed = scrypt.hashSync(password,
|
|
|
|
{N: 16384, r:8, p:1},
|
|
|
|
32,
|
|
|
|
salt);
|
|
|
|
|
|
|
|
return hashed;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getVerificationHash,
|
|
|
|
getPasswordDerivedKey
|
|
|
|
};
|