Example #1
0
            bcrypt.genSalt(10, function (err, salt) {
                if (err) {
                    next(err);
                }

                bcrypt.hash(attr.password, salt, null, function (err, hash) {

                    if (err) next(err);

                    attr.password = hash;
                    next();

                });
            });
Example #2
0
    bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) {
        if(err) {
            return next(err);
        }

        bcrypt.hash(user.password, salt, null, function(err, hash) {
            if(err) {
                return next(err);
            }

            user.password = hash;
            next();
        });
    });
Example #3
0
	beforeCreate: function (user, next) {
		// This checks to make sure the password and password confirmation match before creating record
		if (!user.password || user.password != user.confirmation) {
		  return next({err: ["Password doesn't match password confirmation."]});
		}

		var bcrypt = require('bcrypt-nodejs');
		//hash(data, salt, progress, callback(err, result))
		bcrypt.hash(user.password, null, null, function(err, encrypted) {
			user.password = encrypted;
			// console.log('Encrypted: ' + user.password);
			next();
		});
	},
Example #4
0
	bcrypt.genSalt(5, function(err, salt) {
    if (err) {
    	return cb(err);
    }

    // Hash password
    bcrypt.hash(user.password, salt, null, function(err, hash) {
      if (err) {
      	return cb(err);
      }
      user.password = hash;
      cb();
    });
  });
Example #5
0
        bcrypt.genSalt(10, function(err, salt) {
          if (err) { return next(err); }

          // hash our password using the salt
          bcrypt.hash(user.password, salt, null, function(err, hash) {
            if (err) { return next(err); }

            // overwrite plain text password with encrypted password
            user.password = hash;
            console.log("USER.PASSWORD, ", user.password);
            // go ahead and save the model
            next();
          });
        });
Example #6
0
                add: function(onSuccess, onError){
                    var name = this.name;
                    var email = this.email;
                    var password = this.password;
                    var role = this.role;

                    //password hashing
                    bcrypt.hash(password, null, null ,function(err, hash){
                        User.build({name: name, email: email, password: hash, role: role})
                            .save()
                            .then(onSuccess)
                            .catch(onError);
                    });
                },
Example #7
0
  bcrypt.genSalt(10, function(err, salt) {
    if(err) {
      return next(err);
    }
    bcrypt.hash(password, salt , null, function(err, hash) {
      if(err) {
        return next(err);
      }

      user.password = hash;
      user.salt = salt;
      next();
    });
  });
Example #8
0
UserSchema.pre('save',function(next){
    
    var user = this;
    
    if(!user.isModified('password')) return next;
    
    bcrypt.hash(user.password,null,null,function(err,hash){
        if(err) next(err);
        user.password = hash;
        next()
    })
    
    
});
Example #9
0
  bcrypt.genSalt(10, function (err, salt) {
    if (err) {
      return next(err)
    }

    bcrypt.hash(_this.password, salt, null, function (err, hash) {
      if (err) {
        return next(err)
      }

      _this.password = hash
      next()
    })
  })
Example #10
0
  bcrypt.genSalt(5, function(err, salt) {

    if (err) return next(err);

    bcrypt.hash(user.password, salt, null, function(err, hash) {

      if (err) return next(err);

      user.password = hash;

      next();

    });
  });
Example #11
0
  bcrypt.genSalt(10, function(err, salt) {
    if (err) {
        return callback(err);
    }

    bcrypt.hash(user.password, salt, null, function(err, hash) {
      if (err) {
          return callback(err);
      }

      user.password = hash;
      callback();
    });
  });
  bcrypt.genSalt(10, function(err, salt) {
      if(err){ return next(err); }

      // hash (encrypt) our password using the salt
      bcrypt.hash(user.password, salt, null, function(err, hash){
          if(err) { return next(err); }

          // Overwrite plain text password with encrypted password
          user.password = hash;

          // Go ahead and save the model
          next();
      });
  });
Example #13
0
        bcrypt.compare( current_password, user.password, function(err, result) {

          if (!result){
            return res.json( jsonErr("The current password isn't correct") );
          }

          bcrypt.hash(new_password, null, null, function(err, hash) {
            //Update new password
            user.password = hash;
            user.save();

            return res.json( jsonSucc( _this.removeSecretFields(user.toObject())) );
          });
        });
Example #14
0
 UserSchema.pre('save', function(next) {
 	var user = this;

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

 	// generate the hash
 	bcrypt.hash(user.password, null, null, function(err, hash) {
 		if (err) return next(err);
 		// change the password to the hashed version
 		user.password = hash;
 		next();
 	});
 });
Example #15
0
        db.exists(userHash, function(err, userExists) {
          if(userExists == false) {
            if(req.body.password == req.body.confirmPassword) {
              // create password hash for account
              bcrypt.hash(req.body.password, null, null, function(err, pHash) {
                var m = db.multi(),
                    senderHash = 'user:'******':invites', 1, req.body.code);
                m.del(iHash);

                // create user hashmap
                m.hmset(userHash, [
                  'admin', false,
                  'inviteQuota', 20,
                  'password', pHash
                ]);

                m.exec(function(err, replies) {
                  auth.startSession(req, res);
                });
              });
            }
            else {
              if(req.apiRequest) {
                res.apiMessage(true, "Passwords do not match.");
              }
              else {
                res.render('register', {
                  'error': "Passwords do not match.",
                  'code': req.body.code,
                  'user': req.body.user
                });
              }
            }
          }
          else {
            if(req.apiRequest) {
              res.apiMessage(true, "Sorry. That user name is already taken.");
            }
            else {
              res.render('register', {
                'error': "Sorry. That user name is already taken.",
                'code': req.body.code,
                'user': req.body.user
              });
            }
          }
        });
Example #16
0
function password(data) {
	var password = data.data.userPassword;
	var testCharFirst = password.substr(0, 1);
	var testCharLast = password.substr(-1, 1);

	log.debug('Checking to see if password is present and encrypted.');
	
	if(testCharFirst == '[' && testCharLast == ']') {
		log.debug('Present and encrypted, moving on!');
		data.config.user = {
			id: 1,
			username: (data.data.username) ? data.data.username : '',
			password: password.substr(1, password.length - 2)
		};

		return when.resolve(data);
	} else {
		log.debug('Going to attempted to encrypt password and re-save config file.');

		var promise = when.defer();

		bcrypt.hash(password, data.config.salt, false, function(err, hash) {
			if(err) return promise.reject(err);

			fs.readFile(paths.app + '/config.js', function(err, file) {
				if(err) return promise.reject(err);

				var tempHash = hash.replace('$1', '$!!1').replace('$2', '$!!2');
				var re = new RegExp('"userPassword":(\\s*)(["\']+)' + password + '(["\']+)');
				var res = file = String(file).replace(re, '"userPassword":$1$2[' + tempHash + ']$3').replace(tempHash, hash);

				fs.writeFile(paths.app + '/config.js', file, function(err) {
					if(err) return promise.reject(err);
					log.debug('New encrypted password save in config file.');

					data.config.user = {
						id: 1,
						username: (data.data.username) ? data.data.username : '',
						password: hash
					};
					promise.resolve(data);
				});

			});
		});

		return promise.promise;
	}
}
Example #17
0
 bcrypt.genSalt(SALT_WORK_FACTOR, function (err, salt) {
   if (err) {
     return next(err);
   }
   // hash the password along with our new salt
   bcrypt.hash(admin.password, salt, null, function (err, hash) {
     if (err) {
       return next(err);
     }
     // override the cleartext password with the hashed one
     admin.password = hash;
     admin.salt = salt;
     next();
   });
 });