How to use the bcrypt.genSaltSync function in bcrypt

To help you get started, we’ve selected a few bcrypt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lupyana / Ride-My-Way / backend / src / controllers / UserController.js View on Github external
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' });
        }
github damian-pastorini / reldens / packages / game / server / password-manager.js View on Github external
encryptPassword(receivedPassword)
    {
        this.saltRounds = 10;
        // generate the password hash:
        let salt = bcrypt.genSaltSync(this.saltRounds);
        return bcrypt.hashSync(receivedPassword, salt);
    }
github liamks / Drawbridge.js / lib / drawbridge.js View on Github external
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 );
  

}
github bipio-server / bipio / src / models / account_auth.js View on Github external
function strCryptSync(str) {
  return bcrypt.hashSync(str, bcrypt.genSaltSync(10));
}
github themostaza / koa-starter / src / utils / crypto.js View on Github external
exports.hashPassword = password => {
  const salt = bcrypt.genSaltSync();
  const hash = bcrypt.hashSync(password, salt);
  return hash;
};
github openhab / openhab-cloud / models / user.js View on Github external
}).set(function (password) {
        this._password = password;
        var salt = this.salt = bcrypt.genSaltSync(10);
        this.hash = bcrypt.hashSync(password, salt);
    });
github tableflip / guvnor / lib / web / index.js View on Github external
CLI.prototype._generateSalt = function (config) {
  config.salt = bcrypt.genSaltSync()
}
github raphaellima8 / typescript-api / server / model / initUserModel.ts View on Github external
function hashPass(user) {
    const salt = bcrypt.genSaltSync(10);
    user.set('password', bcrypt.hashSync(user.password, salt));
  }
github es / OnlineJudge / app / models / user.js View on Github external
encryptPassword: function(password) {
                    if (!password) return '';
                    return bcrypt.hashSync (password, bcrypt.genSaltSync(SALT_WORK_FACTOR));
                }
            }
github komarserjio / notejam / express / notejam / routes / users.js View on Github external
function generateHash(password) {
  return bcrypt.hashSync(password, bcrypt.genSaltSync(10));
}