mirror of
https://github.com/zadam/trilium.git
synced 2024-12-24 08:13:53 +08:00
fix password change
This commit is contained in:
parent
e1251222cc
commit
a73afa9ded
4 changed files with 6 additions and 10 deletions
|
@ -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.")
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue