const bcrypt = require('bcrypt'); module.exports = function (sequelize, DataTypes, options) { const model = sequelize.define("password", { id: { type: DataTypes.STRING, defaultValue: function() { return options.generateUniqueId() }, primaryKey: true, unique: true }, password: { type: DataTypes.STRING, // primaryKey: true, unique: true, allowNull: false, set(val) { var hashedPassword = options != null && val != null && val.length > 0 ? bcrypt.hashSync(val, bcrypt.genSaltSync(11)) : null ; this.setDataValue('password', hashedPassword); } // should have an accessor method the redacts this failed... } }, { comment: "hashed password" }); model.associate = (db) => { model.User = model.belongsTo(db.User); } return model; };