2017-10-21 21:10:33 -04:00
|
|
|
"use strict";
|
|
|
|
|
2018-04-01 21:27:46 -04:00
|
|
|
const optionService = require('./options');
|
2018-10-14 11:48:29 +02:00
|
|
|
const crypto = require('crypto');
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function getVerificationHash(password) {
|
|
|
|
const salt = optionService.getOption('passwordVerificationSalt');
|
2017-10-14 23:31:44 -04:00
|
|
|
|
|
|
|
return getScryptHash(password, salt);
|
|
|
|
}
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function getPasswordDerivedKey(password) {
|
|
|
|
const salt = optionService.getOption('passwordDerivedKeySalt');
|
2017-10-14 23:31:44 -04:00
|
|
|
|
|
|
|
return getScryptHash(password, salt);
|
|
|
|
}
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function getScryptHash(password, salt) {
|
2018-10-14 11:48:29 +02:00
|
|
|
const hashed = crypto.scryptSync(password, salt, 32,
|
|
|
|
{N: 16384, r:8, p:1});
|
2017-10-14 23:31:44 -04:00
|
|
|
|
|
|
|
return hashed;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getVerificationHash,
|
|
|
|
getPasswordDerivedKey
|
2020-06-20 12:31:38 +02:00
|
|
|
};
|