Пример #1
0
 "compare": function(test) {
     var salt1 = bcrypt.genSaltSync(),
         hash1 = bcrypt.hashSync("hello", salt1); // $2a$
     var salt2 = bcrypt.genSaltSync();
     salt2 = salt2.substring(0,2)+'y'+salt2.substring(3); // $2y$
     var hash2 = bcrypt.hashSync("world", salt2);
     bcrypt.compare("hello", hash1, function(err, same) {
         test.notOk(err);
         test.ok(same);
         bcrypt.compare("hello", hash2, function(err, same) {
             test.notOk(err);
             test.notOk(same);
             bcrypt.compare("world", hash2, function(err, same) {
                 test.notOk(err);
                 test.ok(same);
                 bcrypt.compare("world", hash1, function(err, same) {
                     test.notOk(err);
                     test.notOk(same);
                     test.done();
                 });
             });
         });
     });
 },
Пример #2
0
  signPost : (req, res, next) => {
    const fields = Object.assign({}, req.body);
    const saltValue = 10;
    const salt = bcrypt.genSaltSync(saltValue);
    const hash = bcrypt.hashSync(req.body.password, salt);

    fields.password = hash;

    const user = new User(fields);
    user.save()
      .then((updatedUser) => {
        res.json(updatedUser)
      })
      .catch((error) => {
        error.statusCode = 404;
        next(error)
      })
  },
Пример #3
0
 "getRounds": function(test) {
     var hash1 = bcrypt.hashSync("hello", bcrypt.genSaltSync());
     test.equal(bcrypt.getRounds(hash1), 10);
     test.done();
 },
Пример #4
0
 test.doesNotThrow(function() {
     bcrypt.hashSync("hello", 10);
 });