26 lines
607 B
JavaScript
26 lines
607 B
JavaScript
"use strict";
|
|
|
|
var bcrypt = require('bcrypt-nodejs');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
//The id field is auto added and made primary key.
|
|
return sequelize.define('User', {
|
|
login: {
|
|
type: DataTypes.STRING
|
|
},
|
|
password: {
|
|
type: DataTypes.STRING
|
|
}
|
|
}, {
|
|
freezeTableName: true, // Model tableName will be the same as the model name
|
|
instanceMethods: {
|
|
generateHash: function(password) {
|
|
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
|
|
},
|
|
validPassword: function(password) {
|
|
return bcrypt.compareSync(password, this.password);
|
|
}
|
|
}
|
|
});
|
|
};
|