-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.js
33 lines (31 loc) · 984 Bytes
/
reset.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
const bcrypt = require('bcryptjs');
SALT_WORK_FACTOR = 10;
require('dotenv').config();
// make sure password is different from old one?
module.exports = {
reset: (req, res, model) => {
let password = req.body.newPassword;
bcrypt.genSalt(SALT_WORK_FACTOR, (err, salt) => {
bcrypt.hash(password, salt, (err, cipher) => {
model
.updateOne(
{ username: req.body.givenUsername },
{
$set: {
password: cipher,
tryPasswordAttempts: 0,
resetPasswordHash: null,
resetPasswordHashExpires: null,
resetPasswordHashIssueDate: null,
lastTimeUpdatedPassword: new Date(),
},
}
)
.catch((err) => res.status(422).json(err));
if (err) console.error(err);
res.json('Your password has been successfully reset.');
});
if (err) console.error(err);
});
},
};