Advertisement
Guest User

Untitled

a guest
May 5th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. function validateUser(req, res) {
  2. var user = req.user;
  3. var currentPassword = req.body.currentPassword;
  4. var newPassword = req.body.newPassword;
  5. var newPasswordConfirmation = req.body.newPasswordConfirmation;
  6.  
  7. bcrypt.hash(currentPassword, ENCRYPTION_PASSES, (err, hash) => {
  8. if(err) return failure(req, res);
  9. console.log("Provided Password: " + currentPassword);
  10. db.get("SELECT cryptedPassword FROM users WHERE username = ?", user.username, (err, row) => {
  11. if(err) failure(req, res, error);
  12. if(row.cryptedPassword != hash) failure(req, res, "Incorrect password");
  13.  
  14. if(typeof newPassword !== "string" || newPassword.length < 10)
  15. return failure(req, res, "Password must be at least ten characters in length");
  16. if(newPassword !== newPasswordConfirmation)
  17. return failure(req, res, "New Password and New Password Confirmation must match");
  18.  
  19. user.password = newPassword;
  20. console.log("New Password: " + user.password);
  21. createPasswordHash(req, res, user);
  22. });
  23. });
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement