2017-10-22 09:10:33 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-04-02 09:27:46 +08:00
|
|
|
const optionService = require('./options');
|
2018-10-14 17:48:29 +08:00
|
|
|
const crypto = require('crypto');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
|
|
|
async function getVerificationHash(password) {
|
2018-04-03 09:47:46 +08:00
|
|
|
const salt = await optionService.getOption('passwordVerificationSalt');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
|
|
|
return getScryptHash(password, salt);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getPasswordDerivedKey(password) {
|
2018-04-03 09:47:46 +08:00
|
|
|
const salt = await optionService.getOption('passwordDerivedKeySalt');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
|
|
|
return getScryptHash(password, salt);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getScryptHash(password, salt) {
|
2018-10-14 17:48:29 +08:00
|
|
|
const hashed = crypto.scryptSync(password, salt, 32,
|
|
|
|
{N: 16384, r:8, p:1});
|
2017-10-15 11:31:44 +08:00
|
|
|
|
|
|
|
return hashed;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getVerificationHash,
|
|
|
|
getPasswordDerivedKey
|
|
|
|
};
|