Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bcrypt.genSalt(12, function(err, salt) { //encrypt the password
// see: https://github.com/nelsonic/bcrypt
bcrypt.hash(req.payload.password, salt, function(err, hash) {
person.password = hash;
ES.CREATE(person, function (res) {
Hoek.assert(res.created, 'Person NOT Registered!'); // only if DB fails!
// transfer any anonymous timers & session to the person
console.log(' - - - - - - - - - - person')
console.log(person);
console.log(' - - - - - - - - - - email success')
email(person, function(err, eres){
console.log(eres);
if(req.headers.authorization){
// console.log("AUTH TOKEN:"+req.headers.authorization);
return transfer(req, reply);
}
async register(
root: any,
{ input }: { input: RegisterInput },
ctx: Context,
): Promise> {
let user;
try {
user = await UserModel.create({
name: input.name,
password: await bcrypt.hash(input.password, 10),
});
} catch (ex) {
if (ex.code === 11000) {
// WriteError of type KeyError
throw new Error(`User ${input.name} already exists`);
}
throw new Error('User could not be created');
}
const session = await SessionModel.create({
user: user.id,
});
ctx.state.session = session;
ctx.state.viewer = user;
return session;
bcrypt.genSalt(12, function(err, salt) {
if (err) {
return fn(err);
}
user.salt = salt;
bcrypt.hash(user.pass, salt, function(err, hash) {
if (err) {
return fn(err);
}
// Set hash so it'll be saved
user.pass = hash;
fn();
});
});
};
Person.hook('beforeSave', function(user) {
// Only hash the password if it has been modified (or is new)
if (user.changed('password')) {
return bcrypt.hash(user.password, BCRYPT_WORK_FACTOR).then(function(hash) {
// Override the cleartext password with the hashed one
user.password = hash;
});
}
});
async function hashPassword(next) {
const user = this;
if (user && user.isModified('password')) {
try {
const salt = await bcrypt.genSalt(5);
user.password = await bcrypt.hash(user.password, salt, null);
return next();
} catch (err) {
return next(err);
}
} else {
return next();
}
}
User.hashPassword = async (user) => {
const hash = await bcrypt.hash(user.password, SALT_ROUNDS);
return user.setDataValue('password', hash);
};
bcrypt.genSalt(10, function(err, salt) {
if (err) {
if (!_.isEmpty(sails.sentry)) {
sails.sentry.captureMessage(err)
} else {
sails.log.warn(err)
}
callback(err, null)
}
bcrypt.hash(newPassword, salt, function(err, hash) {
if (err) {
if (!_.isEmpty(sails.sentry)) {
sails.sentry.captureMessage(err)
} else {
sails.log.warn(err)
}
}
callback(err, hash)
})
})
exports.seed = async function(knex, Promise) {
//Make 10 users using faker. Note: we're also bcrypting
//the passwords to make it exactly like the real app. All their
//passwords will be 'secret'
let seedData = []
for (let i = 0; i < 5; i++) {
let password = 'demopassword'
try {
password = await bcrypt.hash(password, 12)
} catch (error) {
throw new Error('PASSWORD_ENCRIPTION_ERROR')
}
if (i === 0) {
let testUser = {
token: 'qwertyuiop',
firstName: 'DemoFirstName',
lastName: 'DemoLastName',
username: 'demousername',
email: 'demoemail@example.com',
password: password,
}
seedData.push(testUser)
continue
}
async registerUser(user: User): Promise {
const actualUser = await this.findOne(user.username!);
if (actualUser) {
throw new Error('User already exists');
}
const salt = await genSalt(12);
const hashPass = await hash(user.password, salt);
return plainToClass(
User,
await this.userRepository.save({
username: user.username,
password: hashPass,
role: roles.USER,
}),
);
}
}