-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.js
34 lines (29 loc) · 1.16 KB
/
input.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const readline = require('readline');
const { encryptPassword, storeEncryptedPassword, deriveEncryptionKeyFromPassword } = require('./user-password');
let encryptionKey = null; // Store the encryption key for reuse
async function authorizeUser() {
if (!encryptionKey) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
return new Promise((resolve, reject) => {
rl.question('Enter your password: ', async (password) => {
rl.close();
try {
// Encrypt the password and store it
const encryptedPassword = encryptPassword(password);
storeEncryptedPassword(encryptedPassword);
// Derive the encryption key from the encrypted password
encryptionKey = await deriveEncryptionKeyFromPassword(encryptedPassword);
resolve(encryptionKey);
} catch (error) {
reject(error);
}
});
});
} else {
return encryptionKey;
}
}
module.exports = { authorizeUser };