2017-12-04 11:29:23 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const options = require('../../services/options');
|
|
|
|
const sql = require('../../services/sql');
|
|
|
|
const utils = require('../../services/utils');
|
|
|
|
const my_scrypt = require('../../services/my_scrypt');
|
|
|
|
const password_encryption = require('../../services/password_encryption');
|
|
|
|
|
2018-03-31 05:07:41 +08:00
|
|
|
async function setup(req) {
|
2017-12-04 11:29:23 +08:00
|
|
|
const { username, password } = req.body;
|
|
|
|
|
2018-03-31 05:07:41 +08:00
|
|
|
await options.setOption('username', username);
|
2017-12-04 11:29:23 +08:00
|
|
|
|
2018-03-31 05:07:41 +08:00
|
|
|
await options.setOption('password_verification_salt', utils.randomSecureToken(32));
|
|
|
|
await options.setOption('password_derived_key_salt', utils.randomSecureToken(32));
|
2017-12-04 11:29:23 +08:00
|
|
|
|
2018-03-31 05:07:41 +08:00
|
|
|
const passwordVerificationKey = utils.toBase64(await my_scrypt.getVerificationHash(password));
|
|
|
|
await options.setOption('password_verification_hash', passwordVerificationKey);
|
2017-12-04 11:29:23 +08:00
|
|
|
|
2018-03-31 05:07:41 +08:00
|
|
|
await password_encryption.setDataKey(password, utils.randomSecureToken(16));
|
2017-12-04 11:29:23 +08:00
|
|
|
|
|
|
|
sql.setDbReadyAsResolved();
|
2018-03-31 05:07:41 +08:00
|
|
|
}
|
2017-12-04 11:29:23 +08:00
|
|
|
|
2018-03-31 05:07:41 +08:00
|
|
|
module.exports = {
|
|
|
|
setup
|
|
|
|
};
|