Advertisement
Guest User

Untitled

a guest
May 26th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. User Model
  2.  
  3. schema: true,
  4. attributes: {
  5. userName: {
  6. type: 'string',
  7. required: true,
  8. },
  9. encryptedPassword: {
  10. type: 'string'
  11. },
  12. toJSON: function() {
  13. var obj = this.toObject();
  14. delete obj.encryptedPassword;
  15. return obj;
  16. }
  17. },
  18.  
  19. install
  20. var CryptoJS = require("crypto-js");
  21.  
  22. beforeCreate: function(values, next) {
  23. // Encrypt
  24. var ciphertext = CryptoJS.SHA256(values.encryptedPassword).toString();
  25. values.encryptedPassword = ciphertext;
  26. next();
  27. }
  28.  
  29.  
  30. Create User
  31. User.create({username: 'Matt20', encryptedPassword:'password'}).exec((err,created) =>{
  32. console.log('Created :');
  33. console.log(created);
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement