-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt.js
39 lines (25 loc) · 892 Bytes
/
encrypt.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
35
36
37
38
39
const db = require('./models/db.js');
const User = require('./models/UserModel.js');
// import module `bcrypt`
const bcrypt = require('bcrypt');
const saltRounds = 10;
const usernames = []; // insert usernames here
db.connect();
async function encryptAccounts() {
for (var i = 0; i < usernames.length; i++) {
var username = usernames[i];
var result = await db.findOne(User, { username: username });
console.log(result);
var password = result.password;
if (result) {
await hashPassword(username, password);
}
}
}
async function hashPassword(username, password) {
bcrypt.hash(password, saltRounds, async function (err, hash) {
var flag = await db.updateOne(User, { username: username }, { password: hash });
console.log('Hashed pw for ' + username + ' ' + hash);
});
}
encryptAccounts();