Skip to content

Instantly share code, notes, and snippets.

@maxnathaniel
Created October 14, 2015 15:52
Show Gist options
  • Save maxnathaniel/9d229e73fd2d5a1304a7 to your computer and use it in GitHub Desktop.
Save maxnathaniel/9d229e73fd2d5a1304a7 to your computer and use it in GitHub Desktop.
User Model
var bcrypt = require('bcrypt-nodejs');
module.exports = function(sequelize, DataTypes) {
return sequelize.define('users', {
username: {
type: DataTypes.STRING,
unqiue: true
},
password: DataTypes.STRING,
role: DataTypes.STRING
},
{
classMethods: {
generateHash: function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null)
},
},
instanceMethods: {
validPassword: function(password) {
return bcrypt.compareSync(password, this.password);
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment