How to use the bcryptjs.hash 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 hoangvvo / nextjs-mongodb-app / pages / api / user / password / reset / [token].js View on Github external
handler.put(async (req, res) => {
  // password reset
  if (!req.body.password) return res.status(400).end();
  const { value: tokenDoc } = await req.db
    .collection('tokens')
    .findOneAndDelete({ _id: req.query.token, type: 'passwordReset' });

  if (!tokenDoc) {
    return res.status(200).json({
      status: 'error',
      message: 'This link may have been expired.',
    });
  }

  const password = await bcrypt.hash(req.body.password, 10);

  await req.db
    .collection('users')
    .updateOne({ _id: tokenDoc.userId }, { $set: { password } });

  return res.json({ message: 'Your password has been updated.' });
});
github zmts / lovefy-api-nodejs / api / middleware / auth.js View on Github external
bcrypt.genSalt(10, function (error, salt) {
                bcrypt.hash(password, salt, function (error, hash) {
                    if (error) return res.status(400).json({ success: false, description: error });
                    req.body.password_hash = hash; // 'password_hash' transfers and saves to DB
                    delete req.body.password || req.body.newPassword;
                    next();
                });
            });
        }
github prisma-labs / graphql-prisma-typescript / src / resolvers / Mutation / account.ts View on Github external
async signup(parent, args, context, info) {
    const res = await context.remote.delegateMutation(
      'createUser',
      args,
      context,
      info,
    )
    const variables = {
      ...args,
      password: await bcrypt.hash(args.password, 10),
    }
    context.remote.request(
      `mutation ($email: String! $firstName: String! $lastName: String! $password: String! $phone: String!) {
          createUser(
            email: $email
            firstName: $firstName
            lastName: $lastName
            password: $password
            phone: $phone
          ) {
            id
          }
        }`,
      variables,
    )
    return context.remote.delegateQuery('User', { id: res.id }, context, info)
github duluca / minimal-mean / server / src / models / user.ts View on Github external
bcrypt.genSalt(10, function(err, salt) {
        if (err) {
          return reject(err)
        }
        bcrypt.hash(newPassword, salt, function(err, hash) {
          if (err) {
            return reject(err)
          }
          resolve(hash)
        })
      })
    })
github gaeduron / Matcha / server / models / users.js View on Github external
const hashPassword = async (password) => {
	let salt = await bcrypt.genSalt(10);
	let hash = await bcrypt.hash(password, salt);

	return hash;
};
github developer239 / node-type-orm-graphql / src / modules / Auth / services / crypto.ts View on Github external
hashPassword(password: string) {
    return bcrypt.hash(password, 12)
  },
  comparePasswords(plaintext: string, cipherText: string) {
github uuchat / uuchat / src / server / controllers / customerSuccessController.js View on Github external
function hashPasswdWithSalt(passwd, callback) {
    bcrypt.hash(passwd, nconf.get('bcrypt_rounds') || 8, callback);
}
github camelaissani / loca / backend / managers / loginmanager.js View on Github external
function createAccount(firstname, lastname, email, password, done) {
        bcrypt.hash(password, 10, (err, hash) => {
            if (err) {
                logger.error(ResponseTypes.ENCRYPT_ERROR + ': ' + err);
                done({status: ResponseTypes.ENCRYPT_ERROR});
                return;
            }

            const account = {
                email: email.toLowerCase(),
                password: hash,
                firstname: firstname,
                lastname: lastname
            };
            accountModel.add(account, done);
        });
    }
github hackern0v1c3 / MacMon / appcode / controllers / db.js View on Github external
bcrypt.genSalt(parseInt(process.env.HASH_STRENGTH), function(err, salt) {
			if(err){return cb(err);}
			
			bcrypt.hash(userPassword, salt, function(err, hash) {
				if(err){return cb(err);}
		
				pool.getConnection(function(err, connection) {
					if(err){return cb(err);}
					connection.query('INSERT INTO users (userName, userPass, userRole) VALUES (?, ?, ?)', [userName, hash, userRole], function (err, results, fields) {
						connection.release();
						if(err){return cb(err);}
						return cb(null);
					}); 
				});
			});
		});
	},
github benawad / graphql-typescript-stripe-example / server / src / resolvers.ts View on Github external
register: async (_, { email, password }) => {
      const hashedPassword = await bcrypt.hash(password, 10);
      await User.create({
        email,
        password: hashedPassword
      }).save();

      return true;
    },
    login: async (_, { email, password }, { req }) => {

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