mirror of
https://github.com/zadam/trilium.git
synced 2024-11-17 21:21:40 +08:00
33 lines
No EOL
1,023 B
JavaScript
33 lines
No EOL
1,023 B
JavaScript
"use strict";
|
|
|
|
const sql = require('./sql');
|
|
const optionService = require('./options');
|
|
const myScryptService = require('./my_scrypt');
|
|
const utils = require('./utils');
|
|
const passwordEncryptionService = require('./password_encryption');
|
|
|
|
async function changePassword(currentPassword, newPassword) {
|
|
if (!await passwordEncryptionService.verifyPassword(currentPassword)) {
|
|
return {
|
|
success: false,
|
|
message: "Given current password doesn't match hash"
|
|
};
|
|
}
|
|
|
|
const newPasswordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(newPassword));
|
|
const decryptedDataKey = await passwordEncryptionService.getDataKey(currentPassword);
|
|
|
|
await sql.transactional(async () => {
|
|
await passwordEncryptionService.setDataKey(newPassword, decryptedDataKey);
|
|
|
|
await optionService.setOption('passwordVerificationHash', newPasswordVerificationKey);
|
|
});
|
|
|
|
return {
|
|
success: true
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
changePassword
|
|
}; |