encrypt.js 744 B

12345678910111213141516171819202122232425
  1. var bcrypt, encryptionUtil;
  2. bcrypt = require('bcrypt');
  3. var salt = "$2a$10$4u0KgeI40vhqD4DN73Ljsu"
  4. // This is a simplistic password encryption helper that uses bcrypt.
  5. encryptionUtil = {
  6. encryptPassword: function(password) {
  7. var encryptedPassword;
  8. if (salt == null) {
  9. salt = bcrypt.genSaltSync();
  10. }
  11. encryptedPassword = bcrypt.hashSync(password, salt);
  12. return {
  13. salt: salt,
  14. encryptedPassword: encryptedPassword
  15. };
  16. },
  17. comparePassword: function(password, encryptedPasswordToCompareTo) {
  18. var encryptedPassword;
  19. encryptedPassword = this.encryptPassword(password, salt).encryptedPassword;
  20. return encryptedPassword === encryptedPasswordToCompareTo;
  21. }
  22. };
  23. module.exports = encryptionUtil;