fix password change

This commit is contained in:
azivner 2017-11-06 19:48:02 -05:00
parent e1251222cc
commit a73afa9ded
4 changed files with 6 additions and 10 deletions

View file

@ -87,15 +87,15 @@ settings.addModule((function() {
contentType: "application/json",
success: result => {
if (result.success) {
alert("Password has been changed. Trilium will be reloaded after you press OK.");
// encryption password changed so current encryption session is invalid and needs to be cleared
encryption.resetEncryptionSession();
encryption.setEncryptedDataKey(result.new_encrypted_data_key);
message("Password has been changed.");
}
else {
message(result.message);
error(result.message);
}
},
error: () => error("Error occurred during changing password.")

View file

@ -7,7 +7,7 @@ const changePassword = require('../../services/change_password');
const auth = require('../../services/auth');
router.post('/change', auth.checkApiAuth, async (req, res, next) => {
const result = await changePassword.changePassword(req.body['current_password'], req.body['new_password']);
const result = await changePassword.changePassword(req.body['current_password'], req.body['new_password'], req);
res.send(result);
});

View file

@ -8,7 +8,7 @@ const audit_category = require('./audit_category');
const crypto = require('crypto');
const aesjs = require('./aes');
async function changePassword(currentPassword, newPassword, req = null) {
async function changePassword(currentPassword, newPassword, req) {
const current_password_hash = utils.toBase64(await my_scrypt.getVerificationHash(currentPassword));
if (current_password_hash !== await options.getOption('password_verification_hash')) {
@ -37,12 +37,8 @@ async function changePassword(currentPassword, newPassword, req = null) {
const digest = crypto.createHash('sha256').update(plainTextBuffer).digest().slice(0, 4);
console.log("Digest:", digest);
const encryptedBytes = aes.encrypt(Buffer.concat([digest, plainTextBuffer]));
console.log("Encrypted", encryptedBytes);
return utils.toBase64(encryptedBytes);
}

View file

@ -41,7 +41,7 @@ function hmac(secret, value) {
}
function browserId(req) {
return req.get('x-browser-id');
return req == null ? null : req.get('x-browser-id');
}
function isElectron() {