How to use the bcryptjs.compare 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 meseven / node-egitimi-movie-api / routes / index.js View on Github external
}, (err, user) => {
		if (err)
			throw err;

		if(!user){
			res.json({
				status: false,
				message: 'Authentication failed, user not found.'
			});
		}else{
			bcrypt.compare(password, user.password).then((result) => {
				if (!result){
					res.json({
						status: false,
						message: 'Authentication failed, wrong password.'
					});
				}else{
					const payload = {
						username
					};
					const token = jwt.sign(payload, req.app.get('api_secret_key'), {
						expiresIn: 720 // 12 saat
					});

					res.json({
						status: true,
						token
github nebulade / surfer / src / auth.js View on Github external
// pick the first found
                    var user = items[0];

                    ldapClient.bind(user.dn, password, function (error) {
                        if (error) return callback('Invalid credentials');

                        callback(null, { username: username });
                    });
                });
            });
        });
    } else {
        var users = safe.JSON.parse(safe.fs.readFileSync(LOCAL_AUTH_FILE));
        if (!users || !users[username]) return callback('Invalid credentials');

        bcrypt.compare(password, users[username].passwordHash, function (error, valid) {
            if (error || !valid) return callback('Invalid credentials');

            callback(null, { username: username });
        });
    }
}
github sagefy / sagefy / server2 / routes / users.js View on Github external
router.delete('/:userId', async (req, res) => {
  const validToken = await bcrypt.compare(req.body.token, req.session.token)
  if (!validToken) throw abort(401, 'm0BEbqfntUmuU4z3hkeO9A')
  const { userId: id } = req.params
  if (req.session.user !== id) throw abort(403, 'fmXJKKVWKUaB4rJSQVjkZw')
  const user = await anonymizeUser(id)
  res.json({ user: omit(user, ['password']) })
})
github superchargejs / framework / hashing / bcrypt-hashinator.js View on Github external
async check (value, hash) {
    return Bcrypt.compare(value, hash)
  }
}
github benjsicam / node-graphql-microservices / graphql-gateway / src / resolvers / users / user.mutation.js View on Github external
resolve: async (parent, { data }, { userService, logger }) => {
      logger.info('UserQuery#login.call', data)

      const user = await userService.findOne({
        where: {
          email: data.email
        }
      })

      logger.info('UserQuery#login.check1', isEmpty(user))

      if (isEmpty(user)) {
        return errorUtils.buildError(['Unable to login'])
      }

      const isMatch = await bcrypt.compare(data.password, user.password)

      logger.info('UserQuery#login.check2', !isMatch)

      if (!isMatch) {
        return errorUtils.buildError(['Unable to login'])
      }

      delete user.password

      logger.info('UserQuery#login.result', user)

      return {
        user,
        token: await authUtils.generateToken(user.id)
      }
    }
github tofuness / anistack / helpers / passport.js View on Github external
}, function(err, userDoc) {
			if (err) return new Error('auth db error');
			if (userDoc) {
				bcryptjs.compare(password, userDoc.password, function(err, res) {
					if (res) done(err, userDoc);
					if (!res) done(err, false, 'Sorry, that password is not right.');
				});
			} else {
				done(err, false, 'Sorry, could not find an account with that username.');
			}
		});
	}
github marley-nodejs / Learn-Nodejs-by-building-10-projects / 11_eLearning_System / models / user.js View on Github external
module.exports.comparePassword = function(candidatePassword, hash, callback){
    bcrypt.compare(candidatePassword, hash, function(err, isMatch){
        if(err){
          throw err;
        }

        callback(null, isMatch);
    });
};
github PRINTR3D / formide-client / src / utils / http / index.js View on Github external
FormideClient.db.User.findOne({ email: email }, function (err, user) {
				if (err) return next(err);
				if (!user) return next(null, false, { message: "Incorrect credentials" });

				bcrypt.compare(password, user.password, function(err, isMatch) {
					if(err) return next(err);
					next(null, isMatch ? user : null)
				});
			});
		}));
github NoQuarterTeam / split / packages / api / src / modules / user / user.service.ts View on Github external
async login(data: LoginInput): Promise {
    const user = await this.userRepository.findByEmail(data.email)
    if (!user) throw new Error("Incorrect email or password")
    const isValidPassword = await bcrypt.compare(data.password, user.password)
    if (!isValidPassword) throw new Error("Incorrect email or password")
    return user
  }

bcryptjs

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

MIT
Latest version published 8 years ago

Package Health Score

70 / 100
Full package analysis