Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.' });
});
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();
});
});
}
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)
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)
})
})
})
const hashPassword = async (password) => {
let salt = await bcrypt.genSalt(10);
let hash = await bcrypt.hash(password, salt);
return hash;
};
hashPassword(password: string) {
return bcrypt.hash(password, 12)
},
comparePasswords(plaintext: string, cipherText: string) {
function hashPasswdWithSalt(passwd, callback) {
bcrypt.hash(passwd, nconf.get('bcrypt_rounds') || 8, callback);
}
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);
});
}
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);
});
});
});
});
},
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 }) => {