How to use the bcrypt.compareSync 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 1046224544 / fontend / api / user.js View on Github external
.then(user => {
                if(!user){
                    return res.status(400).json("用户名或密码错误");
                }else{
                    // 校验密码
                    const password = req.body.password;
                    const isValidPassword = bcrypt.compareSync(password, user.password);
                    if(!isValidPassword){
                        return res.status(400).json("用户名或密码错误");
                    }else{

                        UserInfo.findOne({email})
                                .then(userinfo => {
                                        Course.findOne({email})
                                            .then(usercourse => {

                                                // 用户登录日志
                                                const newLogin_Log = new UserLogin_Log({
                                                    email,
                                                    username:userinfo.username,
                                                    loginTime:new Date().format("yyyy/MM/dd HH:mm:ss")
                                                })
                                                newLogin_Log.save();
github liamray / nexl-js / backend / routes / auth / auth-route-impl.js View on Github external
function isTokenValid(username, token) {
	// loading existing token
	var data = confMgmt.load(confMgmt.CONF_FILES.TOKENS);

	// getting specific token for username
	var encryptedToken = data[username];

	// encryptedToken doesn't exist in config ?
	if (encryptedToken === undefined) {
		return false;
	}

	return bcrypt.compareSync(token, encryptedToken);
}
github buzz-software / expressjs-mvp-landing-page / passport_setup.js View on Github external
const validPassword = function(user, password) {
	return bcrypt.compareSync(password, user.password);
}
module.exports = function(passport) {
github embbnux / kails / app / models / user.js View on Github external
User.prototype.authenticate = function(value) {
    if (bcrypt.compareSync(value, this.passwordDigest)){
      return this;
    } else{
      return false;
    }
  };
github littleStudent / micro-authentication-starter / src / authentication / authentication.js View on Github external
return User.find({ username: username }).exec().then((users, err) => {
    if (!users.length) {
      throw createError(401, 'That user does not exist');
    }

    const user = users[0];
    if (!compareSync(password, user.password)) {
      throw createError(401, 'Wrong password');
    }
    return user;
  });
};
github lmarkus / Kraken_Example_Passport / models / user.js View on Github external
userSchema.methods.passwordMatches = function (plainText) {
            var user = this;
            return bcrypt.compareSync(plainText, user.password);
        };
github OWASP / RiskAssessmentFramework / api / src / app / api / controllers / users.js View on Github external
userModel.findOne({ email: req.body.email }, function(err, userInfo) {
      if (err) {
        next(err);
      } else {
        if (bcrypt.compareSync(req.body.password, userInfo.password)) {
          const token = jwt.sign(
            { id: userInfo._id },
            req.app.get("secretKey"),
            { expiresIn: "1h" }
          );
          res.json({
            status: "success",
            message: "user found!!!",
            data: { user: userInfo, token: token }
          });
        } else {
          res.json({
            status: "error",
            message: "Invalid email/password!!!",
            data: null
          });
github IBM / manage-control-device-node-red / index.js View on Github external
authenticate: function(username, password) {
                if (config.adminAuth.username === username && bcrypt.compareSync(password,config.adminAuth.password)) {
                    return when.resolve({username:username,permissions:"*"});
                } else {
                    return when.resolve(null);
                }
            }
        };
github onbjerg / micro-auth-example / index.js View on Github external
.then((users) => {
    if (!users.length) {
      throw createError(401, 'That user does not exist')
    }

    const user = users[0]
    if (!compareSync(password, user.password)) {
      throw createError(401, 'Wrong password')
    }

    return user
  })