Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User Model
- schema: true,
- attributes: {
- userName: {
- type: 'string',
- required: true,
- },
- encryptedPassword: {
- type: 'string'
- },
- toJSON: function() {
- var obj = this.toObject();
- delete obj.encryptedPassword;
- return obj;
- }
- },
- install
- var CryptoJS = require("crypto-js");
- beforeCreate: function(values, next) {
- // Encrypt
- var ciphertext = CryptoJS.SHA256(values.encryptedPassword).toString();
- values.encryptedPassword = ciphertext;
- next();
- }
- Create User
- User.create({username: 'Matt20', encryptedPassword:'password'}).exec((err,created) =>{
- console.log('Created :');
- console.log(created);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement