.then((exists) => { if (exists) { throw boom.create(401, 'Username already exists'); } return bcrypt.hash(newUser.password, 12); })
.then(function () { if (!admin) admin = false; if (!body.firstname || !body.lastname || !body.username || !body.password || !body.email) reject({ status: 401, msg: 'Missing something' }); return bcrypt.hash(body.password, 10); })
app.post('/register', function(request, response) { var info = request.body; // 1. Use bcrypt to encrypt the user's password bcrypt.hash(info.password, 10) .then(function(encryptedPassword) { return User.create({ _id: info.username, encryptedPassword: encryptedPassword }); }) .then(function(){ console.log("Success"); }) .catch(function(err){ if (err) { var message = formatMongooseError(err); response.json({ status: 'fail', error: message }); } else { // 5. Return ok response response.json({ status: 'ok' }); } }); response.send('no errors'); });
export async function hashWithSalt(pwd) { try { return await bcrypt.hash(pwd); } catch (err) { throw err; } }
userSchema.pre('save', async function preSave(next) { if (!this.password) return next(); try { this.hashed_password = await bcrypt.hash(this.password); next(); } catch ( error ) { next(error); } })
ChallengeSchema.methods.setFlag = async function (plainFlag) { let flagThumb; if (plainFlag.length > 10) { flagThumb = plainFlag.substr(0, 6) + '...' + plainFlag.substr(-4, 4); } else { flagThumb = plainFlag.substr(0, 3) + '...'; } this.flag = await bcrypt.hash(plainFlag, 10); this.flagThumb = flagThumb; };
.then((exists) => { if (exists) { return res .status(409) .set('Content-Type', 'text/plain') .send('Email already exists.'); } return bcrypt.hash(password, 12); })
UserSchema.pre("save", async function preSave(next) { if(!this.password) return next(); try { let salt = await bcrypt.genSalt(); this.hashed_password = await bcrypt.hash(this.password, salt); next(); } catch (err) { next(err); } });
getData({model: Users}).single({email: body.email}).then((results) =>{ if(results.length === 0){ bcrypt.hash(body.password, 10) .then((hash) => body = hash) .then((hash) => { addContent({ content: data, model: Users },req,res,next) }); }else{ res.json({'message': 'This item already exists'}); } });
_createUser(password) { var passHashP = null if(password) passHashP = bcrypt.hash(password, 10) else passHashP = Promise.resolve(null) return passHashP.then( hashed => { return new Promise( (resolve, reject) => { const data = { created: new Date(), passwordHash: hashed } var userKey = this.ds.key("User") this.ds.insert({ key:userKey, data:data }, (error, apiResponse) => { if(error) reject(error) else resolve( {key:userKey, data:data} ) }) }) }) }
mutateAndGetPayload: async (input, context) => { const {email, password, first, last} = input; const {db, session} = context; assert(email.match(/.+@.+?\..+/), 'Email is invalid'); assert(password.length > 5, 'Password is invalid; too short.'); assert(first.length > 0, 'First Name Required.'); assert(last.length > 0, 'Last Name Required.'); const passwordHash = await bcrypt.hash(password, 10); const user = await db.insert('users', { email, passwordHash, first, last, }); session.currentUserID = user.id; return {session}; },
before(async () => { users = usersData() hashed = await hash(password) const protect = _ => (_, res, next) => (res.locals.user = omit(mockUser, 'password')) && next() const onDelete = (_, res) => res.sendStatus(204) const onLogin = (_, res) => res.sendStatus(201) app = express() .use(json()) .post('/api/signup', postUser(users)) .post('/api/authenticate', authenticate(users), onLogin) .use(protect()) .delete('/api/polls/:pollId', checkPollOwner(users), onDelete) .use(errorHandler) client = request(app) })
.then(salt => bcrypt.hash(this.password, salt))
.then(function(salt) { // hash the password using our new salt return bcrypt.hash(user.password, salt); })