How to use the bcrypt.genSalt 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 Kartikkh / We-Donate / models / Ngo / ngo.js View on Github external
module.exports.createNgo = (newNgo, callback)=>{
    bcrypt.genSalt(10, function(err, salt) {
        bcrypt.hash(newNgo.password, salt, function(err, hash) {
            // Store hash in your password DB.
            newNgo.password = hash
            // console.log(hash)
            newNgo.save(callback)
        });
    });
};
github moribvndvs / passport-examples / shared / models / User.js View on Github external
UserSchema.pre('save', function(next) {
  const user = this;

  // only hash the password if it has been modified (or is new)
  if (!user.isModified('password')) {
    return next();
  }

  // generate a salt
  bcrypt.genSalt(WORK_FACTOR, function (err, salt) {
    if (err) return next(err);

    // hash the password along with our new salt
    bcrypt.hash(user.password, salt, function (err, hash) {
      if (err) return next(err);

      // override the cleartext password with the hashed one
      user.password = hash;
      // let mongoose know we're done now that we've hashed the plaintext password
      next();
    });
  });
});
github ahendouz / dribbble-clone / models / User.js View on Github external
UserSchema.pre("save", function(next) {
  // if the password Field on our schema is not modified we want to return next
  if (!this.isModified("password")) {
    return next();
  }
  bcrypt.genSalt(10, (err, salt) => {
    if (err) return next(err);

    bcrypt.hash(this.password, salt, (err, hash) => {
      if (err) return next(err);
      this.password = hash;
      next();
    });
  });
});
github zafar-saleem / timeoff-server / server / models / User.js View on Github external
UserSchema.pre('save', function(next) {
  let user = this;

  if (this.isModified('password') || this.isNew) {
    bcrypt.genSalt(10, (err, salt) => {
      if (err) {
        console.log(err);
        return next(err);
      }

      bcrypt.hash(user.password, salt, (err, hash) => {
        if (err) {
          console.log(err);
          return next(err);
        }

        user.password = hash;
        next();
      });
    });
  } else {
github SlashmanX / xForum / server / modules / account-manager.js View on Github external
AM.saltAndHash = function(pass, callback)
{
	bcrypt.genSalt(10, function(err, salt) {
	    bcrypt.hash(pass, salt, function(err, hash) {
			callback(hash);
	    });
	});
}
github tes / seguir / api / auth / utils.js View on Github external
function hashPassword (password, next) {
  bcrypt.genSalt(10, function (err, salt) {
    if (err) { return next(err); }
    bcrypt.hash(password, salt, next);
  });
}
github alexyoung / nodejsinaction / ch06-connect-and-express / listing6_15-21 / models / user.js View on Github external
hashPassword(cb) {
    bcrypt.genSalt(12, (err, salt) => {
      if (err) return cb(err);
      this.salt = salt;
      bcrypt.hash(this.pass, salt, (err, hash) => {
        if (err) return cb(err);
        this.pass = hash;
        cb();
      });
    });
  }
github os-js / OS.js / src / server / node / modules / auth / database.js View on Github external
return new Promise((resolve, reject) => {
      Bcrypt.genSalt(10, (err, salt) => {
        Bcrypt.hash(user.password, salt, (err, hash) => {
          const q = 'UPDATE `users` SET `password` = ? WHERE `id` = ?;';
          const a = [hash, user.id];

          this.db.query(q, a).then(resolve).catch(reject);
        });
      });
    });
  }
github devonfw / devon4node / samples / employee / src / app / core / user / services / user.service.ts View on Github external
async registerUser(user: User): Promise {
    const actualUser = await this.findOne(user.username!);

    if (actualUser) {
      throw new Error('User already exists');
    }

    const salt = await genSalt(12);
    const hashPass = await hash(user.password, salt);

    return plainToClass(
      User,
      await this.userRepository.save({
        username: user.username,
        password: hashPass,
        role: roles.USER,
      }),
    );
  }
}
github StellarFw / stellar / src / satellites / hash.ts View on Github external
public generateSalt(
    rounds: number = this.api.configs.general.saltRounds,
  ): Promise {
    return bcrypt.genSalt(rounds);
  }