Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import bcrypt from 'bcrypt';
import jwt from 'jsonwebtoken';
import db from '../db/index';
const saltRounds = 10;
const salt = bcrypt.genSaltSync(saltRounds);
const SECRET_KEY = 'secretkey23456';
const expiresIn = 24 * 60 * 60;
const User = {
register(req, res) {
if (!req.body.email || !req.body.password || !req.body.fname || !req.body.lname) {
return res.status(400).send({ message: 'All fields are required' });
}
// Check if existing
const query = 'SELECT * FROM users WHERE email = $1';
db.query(query, [req.body.email])
.then((result) => {
if (result.rows.length > 0) {
return res.status(400).send({ message: 'Email already exists' });
}
encryptPassword(receivedPassword)
{
this.saltRounds = 10;
// generate the password hash:
let salt = bcrypt.genSaltSync(this.saltRounds);
return bcrypt.hashSync(receivedPassword, salt);
}
this.afterLoginFn = function( res, user ){
res.redirect('/');
}
this.dashboard = new Dashboard( this, this.config.signups )
this.waitlist = false;
this.authentication = new Auth( this, this.config.authentication );
if( this.config.signups ){
this.signups( this.config.signups );
this.waitlist = this.config.signups.waitlist;
}
if(this.config.superUser){
var salt = bcrypt.genSaltSync(10),
plainPassword = this.config.superUser.password,
password = bcrypt.hashSync( this.config.superUser.password, salt );
this.config.superUser.password = password;
this.db.createSuperUser( this.config.superUser );
this.config.superUser.password = plainPassword;
}
// critical
this.dashboard.addAuth( this.authentication );
}
function strCryptSync(str) {
return bcrypt.hashSync(str, bcrypt.genSaltSync(10));
}
exports.hashPassword = password => {
const salt = bcrypt.genSaltSync();
const hash = bcrypt.hashSync(password, salt);
return hash;
};
}).set(function (password) {
this._password = password;
var salt = this.salt = bcrypt.genSaltSync(10);
this.hash = bcrypt.hashSync(password, salt);
});
CLI.prototype._generateSalt = function (config) {
config.salt = bcrypt.genSaltSync()
}
function hashPass(user) {
const salt = bcrypt.genSaltSync(10);
user.set('password', bcrypt.hashSync(user.password, salt));
}
encryptPassword: function(password) {
if (!password) return '';
return bcrypt.hashSync (password, bcrypt.genSaltSync(SALT_WORK_FACTOR));
}
}
function generateHash(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(10));
}