I solved this problem using two fields: one of them is the VIRTUAL type, which handles input and verification, and one is the STRING type, which contains the hashed password.
This example is not coffeescript , but you can easily translate it.
password_hash: { type: DatabaseTypes.STRING, allowNull: false, validate: { notEmpty: true, }, }, password: { type: DatabaseTypes.VIRTUAL, allowNull: false,
When authenticating a user, compare the entered password with User.password_hash , not User.password .
instanceMethods: {
You can then call this instance method to authenticate User .
User.findById(userId) .then((user) => { if (user.authenticate(password)) { console.log('Authenticated'); } else { console.log('Not authenticated'); } });
source share