How to use the hashSync function from bcrypt-nodejs

Find comprehensive JavaScript bcrypt-nodejs.hashSync code examples handpicked from public code repositorys.

44
45
46
47
48
49
50
51
52
53
initialize: function() {
  this.on('saving', function(model,attrs,options){
    if (model.get('authType') === 'local'){
      var password = model.get('password');
      var salt = bcrypt.genSaltSync();
      var hash = bcrypt.hashSync(password);
      model.set('password',hash);
    }
  });
}
fork icon0
star icon10
watch icon2

112
113
114
115
116
117
118
119
120
121
122
123
router.post("/register", async (req, res) => {
  let body = req.body;
  try {
    if (!body || typeof body !== "object")
      throw new Error(Enum.HTTP_CODES.UNPROCESSIBLE_ENTITY, i18n.USERS.VALIDATION_ERROR_TITLE, i18n.USERS.VALIDATION_ERROR_INFO);
    body.password = bcrypt.hashSync(body.password, bcrypt.genSaltSync(8), null);


    let superAdminRole = await Roles.findOne({ role_name: "SUPER_ADMIN" });


    if (superAdminRole && superAdminRole._id) {
fork icon0
star icon5
watch icon1

+ 3 other calls in file

40
41
42
43
44
45
46
47
48
49
console.warn("Created default user account. Please change it's password after logging in!")
console.warn("Username: admin")
console.warn("Password: password")
let user = {
    username: 'admin',
    password: bcrypt.hashSync('password', bcrypt.genSaltSync(10)),
    admin: true,
    superuser: true,
    volunteer: true,
    groupId: null,
fork icon0
star icon1
watch icon1

+ 5 other calls in file

432
433
434
435
436
437
438
439
440
441
    SELECT *\
    FROM people_community natural join community\
    WHERE user_Id = ' + req.user.user_Id;
if (form.newPassword == form.repeatPassword) {
    if (bcrypt.compareSync(form.currentPassword, req.user.password)) {
        let passwordHash = bcrypt.hashSync(form.newPassword, null, null);
        let updateQuery = '\
        UPDATE users\
        SET password = \'' + passwordHash + '\' \
        WHERE user_Id = ' + req.user.user_Id;
fork icon0
star icon1
watch icon0

+ 4 other calls in file

1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
database.RunQuery(selectService,Sequelize.QueryTypes.SELECT,(service)=>{
    const selectU="SELECT * FROM Users where Username="+"'"+req.user.Username+"'";
    database.RunQuery(selectU,Sequelize.QueryTypes.SELECT,(admin)=>{
        if (form.newPassword == form.repeatPassword) {
            if (bcrypt.compareSync(form.currentPassword, req.user.Password)) {
                var passwordHash = bcrypt.hashSync(form.newPassword, null, null);
                var updateQuery = '\
                UPDATE Users\
                SET Password = \'' + passwordHash + '\' \
                WHERE UserId = ' + req.user.UserId;
fork icon0
star icon0
watch icon1

+ 7 other calls in file

4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324








function encryptPassword(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(5), null);  
};
             



fork icon0
star icon0
watch icon1

20
21
22
23
24
25
26
27
28
29
30
31
const User = require(path.join(appRoot, 'api/models/User'));


/*
// sync version of hashing function
var myHasher = function(password, tempUserData, insertTempUser, callback) {
  var hash = bcrypt.hashSync(password, bcrypt.genSaltSync(10), null);
  return insertTempUser(hash, tempUserData, callback);
};*/


// async version of hashing function
fork icon0
star icon0
watch icon1

206
207
208
209
210
211
212
213
214


resellerModule.findById(req.params.id, function (err, resl) {
  
  if(resl.Informations.Password != myPassword) 
  {myPassword = bcrypt.hashSync(myPassword) ; console.log("yes") ;}
  if (resl.Contacts.Logo != myLogo && resl.Contacts.Logo != "avatar.png")
    fs.unlink("images\\" + resl.Contacts.Logo, (err) => {});

fork icon0
star icon0
watch icon1

+ 3 other calls in file

10
11
12
13
14
15
16
17
18
19
20
21
    }
    return msg.trim();
}


exports.encrypt = async (password) => {
    return bcrypt.hashSync(password);
}


exports.checkPassword = async (passBody, passUser) => {
    try {
fork icon0
star icon0
watch icon1

+ 3 other calls in file

75
76
77
78
79
80
81
82
83
84
    if(user.length !== 0 ){
        console.log('exist');
        return done('exist', null);
    }
    console.log(`pwd ${password}`);
    let hash = bcrypt.hashSync(password, bcrypt.genSaltSync(6));
    console.log(hash + '1');
    return(hash);
    
}) 
fork icon0
star icon0
watch icon1

+ 5 other calls in file

420
421
422
423
424
425
426
427
428
429
        success: false,
        message: req.__(result.array()[0].msg),
    }));
}
else {
    let oldPassword = bcrypt.hashSync(req.body.oldPassword, Factory.env.BCRYPT_SALT);
    if (oldPassword===req.USER_PASSWORD) {
        let data = {
            password: bcrypt.hashSync(req.body.password, Factory.env.BCRYPT_SALT),
            updatedAt: new Date()
fork icon0
star icon0
watch icon1

+ 7 other calls in file

179
180
181
182
183
184
185
186
187
188
resellerModule
.findOne({"Informations.resetToken" : token ,  "Informations.resetTokenExpiration": { $gt: Date.now() }})
.then((data) => {
  if (data) {
        resetUser = data ;
        resetUser.Informations.Password = bcrypt.hashSync(newPassword);
        resetUser.Informations.resetToken = undefined;
        resetUser.Informations.resetTokenExpiration = undefined;
        resetUser.save();
        return res.status(200).send({'password': 'password updated successfully'});
fork icon0
star icon0
watch icon1

+ 3 other calls in file

55
56
57
58
59
60
61
62
63
64
var message = null;

// Add missing user fields

// hash the password
user.password = bcrypt.hashSync(user.password);

User
  .build(user)
  .save()
fork icon0
star icon0
watch icon1

+ 4 other calls in file

403
404
405
406
407
408
409
410
411
412
		}
	}).catch(function(error) {
		return res.status(200).send({ data:{success:false, details:""}, errorNode:{errorCode:1, errorMsg:error}});
	});
} else {
	var hash = bcrypt.hashSync("123456");
	models.customers.findOne({
		where: {
			[Op.or]: [
				{ email: email },
fork icon0
star icon0
watch icon1

+ 9 other calls in file

321
322
323
324
325
326
327
328
329
330
if (users != null) {
	const jwtsecret = SECRET + users.password;
	try {
		const payload = jwt.verify(token, jwtsecret);
		if(password == password2){
			const passwordhash = bcrypt.hashSync(password);
			models.admins.update({password:passwordhash},{ where: { id: id } });
			req.flash('message', "Password successfully changed");
			return res.redirect('/auth/signin');
		}else{
fork icon0
star icon0
watch icon1

+ 9 other calls in file

1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
if(!id){
    req.flash('errors','Something went wrong');
    return res.redirect('/admin/customers/view/'+id);
} else{
    models.customers.update({
        password: bcrypt.hashSync(fields.password[0]),
        updatedBy: sessionUserId
    },{where:{id:id}}).then(function(value) {
        if(value) {
            req.flash('info','Successfully customer updated');
fork icon0
star icon0
watch icon1

+ 4 other calls in file