Hash a password with bcrypt
Last updated
Last updated
const bcrypt = require('bcrypt');
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
const Users = sequelize.define('users', {
email: {
type: DataTypes.STRING,
},
password: {
type: DataTypes.STRING,
allowNull: true,
// Storing passwords in plaintext in the database is terrible.
// Hashing the value with an appropriate cryptographic hash function is better.
set(value) {
const hash = bcrypt.hashSync(value, 10);
this.setDataValue('password', hash);
},
},
}, {
tableName: 'users',
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});