How to use the bcryptjs.compareSync function in bcryptjs

To help you get started, we’ve selected a few bcryptjs 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 spderosso / deja-vu / catalog / access / standardAuthentication / src / app.ts View on Github external
return Validation.userExists(username).then(user => {
        if (!bcrypt.compareSync(oldPassword, user.password)) {
          throw new Error("Incorrect password");
        }

        const newPasswordHash = bcrypt.hashSync(newPassword, 10);
        const updateOperation = {$set: {password: newPasswordHash}};

        return mean.db.collection("users")
          .updateOne({username: username}, updateOperation)
          .then(write_res => {
            if (write_res.modifiedCount !== 1) {
              throw new Error("Couldn't save new password");
            }

            // report
            return bus.update_atom("User", user.atom_id, updateOperation);
          })
github liangfengbo / nodejs-koa-blog / app / dao / user.js View on Github external
static async verifyEmailPassword(email, plainPassword) {

        // 查询用户是否存在
        const user = await User.findOne({
            where: {
                email
            }
        })

        if (!user) {
            throw new global.errs.AuthFailed('账号不存在')
        }

        // 验证密码是否正确
        const correct = bcrypt.compareSync(plainPassword, user.password);

        if (!correct) {
            throw new global.errs.AuthFailed('密码不正确')
        }

        return user
    }
github spderosso / deja-vu / catalog / access / standardAuthentication / src / app.ts View on Github external
return Validation.userExists(username).then(user => {
        // TODO: promisify
        if (!bcrypt.compareSync(password, user.password)) {
          throw new Error("Incorrect password");
        }
        const token = jwt.sign(username, "ultra-secret-key");
        return JSON.stringify({
          token: token,
          user: user
        });
      });
    }
github eddyystop / feathers-service-verify-reset / test / password_spec.js View on Github external
it('compare plain passwords to encrypted ones', function () {
    this.timeout(9000);

    assert.isOk(bcrypt.compareSync(usersDb[0].plainPassword, usersDb[0].password), '[0]');
    assert.isOk(bcrypt.compareSync(usersDb[1].plainPassword, usersDb[1].password), '[1]');

    assert.isOk(bcrypt.compareSync(usersDb[0].plainNewPassword, usersDb[0].newPassword), 'new [0]');
    assert.isOk(bcrypt.compareSync(usersDb[1].plainNewPassword, usersDb[1].newPassword), 'new [1]');
  });
});
github schahriar / Galleon / tests / B_USER_Management_Tests.js View on Github external
global.galleon.changePassword("hash@example.com", "changetopass", "okpassword", function(error, user) {
			if(error) throw error;
			expect(user.email).to.equal("hash@example.com");
			expect(bcrypt.compareSync("changetopass", user.password)).to.equal(true);
			done();
		})
	})
github djizco / mern-boilerplate / server / database / schemas / User.js View on Github external
userSchema.methods.validPassword = function(password) {
  return bcrypt.compareSync(password, this.password);
};
github pmuens / discuss / backend / lib / graphql / collections / users / resolves.js View on Github external
}).then(result => {
      const Item = result.Items[0];
      if (!Item) return Promise.reject('User not found');

      let match = bcryptjs.compareSync(password, Item.password);
      if (!match) return Promise.reject('invalid password');

      delete Item.password;

      Item.jwt = authenticate(Item);
      Item.gravatar = gravatar.url(Item.email, {s: '100', r: 'x', d: 'retro'}, true);

      return Item;
    });
  },
github secusu / secusu / node_modules_local / chat-server / chat-server.js View on Github external
ChatServer.prototype.isRoomPasswordValid = function (password, hash) {
    var bcrypt = require('bcryptjs');

    return bcrypt.compareSync(password, hash);
};
github sasha7 / notes-app / models / user.js View on Github external
static checkPassword(password, hash) {
    return bcrypt.compareSync(password, hash);
  }
}
github entria / graphql-dataloader-boilerplate-ts / src / modules / user / UserModel.ts View on Github external
authenticate(plainTextPassword: string) {
    return bcrypt.compareSync(plainTextPassword, this.password);
  },
  encryptPassword(password: string) {

bcryptjs

Optimized bcrypt in plain JavaScript with zero dependencies. Compatible to 'bcrypt'.

MIT
Latest version published 7 years ago

Package Health Score

73 / 100
Full package analysis