userModel.findOne({ email: req.body.email }, function (err, userInfo) { if (err) { next(err); } else { if (bcrypt.compareSync(req.body.password, userInfo.password)) { const token = jwt.sign({ id: userInfo._id }, req.app.get('secretKey'), { expiresIn: '1h' }); res.json({ status: "success", message: "user found!!!", data: { user: userInfo, token: token } }); } else { res.json({ status: "error", message: "Invalid email/password!!!", data: null }); } } });
async verify(password: string): Promise<boolean> { // Grab raw data from database to get access to other fields. const user = await db.table('users').where({ email: this.email }).first(); if (!user || !user.password_hash) { return false; } return compareSync(password, user.password_hash); }
// passport local strategy for local-login, local refers to this app passport.use('local-login', new LocalStrategy( function (username, password, done) { console.log("Local-login:" +bcrypt.compareSync(password, users[0].password)); if (username === users[0].username && bcrypt.compareSync(password, users[0].password)) { return done(null, users[0]); } else { return done(null, false, {"message": "User not found."}); } }) );
// find the user data by his username. this.find(username, function(user) { // if there is a user by this username. if(user) { // now we check his password. if(bcrypt.compareSync(password, user.password)) { // return his data. callback(user); return; } } // if the username/password is wrong then return null. callback(null); });
static equals(value, hash) { return bcrypt.compareSync(value, hash); }
User.findOne({'phoneNumber': req.body.phoneNumber}, (err, user) => { if (err) { res.status(404).send(err); } let passwordIsValid = bcrypt.compareSync(req.body.password, user.password); if (passwordIsValid) return res.status(401).send({ auth: false, token: null }); // create a token let token = jwt.sign({ name: user.name, status: user.status }, 'secret'); res.status(200).send({ auth: true, token: token }); })
userdbtier.getUserByEmail(email,function(err, rows){ if (err) return res.json({loggedin: false, message:"no such user found"}); if(!rows.length) return res.json({loggedin: false, message:"no such user found"}); else{ //console.log(rows); if(bcrypt.compareSync(password, rows[0].Password)){ //if(password === rows[0].Password){ // from now on we'll identify the user by the id and // the id is the only personalized value that goes into our token var payload = { id: rows[0].iduser, role: rows[0].Type }; var token = jwt.sign(payload, 'JustaTest', { expiresIn: '30m' }); delete rows[0].Password; delete rows[0].iduser; return res.json({loggedin: true, message: "Login success", email: rows[0].Email, type: rows[0].Type, token: `Bearer ${token}`}); } else return res.json({loggedin: false, message:"Wrong password!"}); } })
sequelize.define("User", { email: DataTypes.STRING, first_name: DataTypes.STRING, last_name: DataTypes.STRING, password: DataTypes.STRING }, { instanceMethods: { comparePassword: function(password, callback) { var match= bcrypt.compareSync(password, this.password); callback(null,match); }, hashPass:function(){ this.password=bcrypt.hashSync(this.password,8); } } })
const getAdminUser = data => User.findOne({ username: data.body.name }).then((res) => { if (res == null) { return false; } const pass = bcrypt.compareSync(data.body.password, res.password); if (pass) { return genAuthTokens(res); } return false; })
passport.use( new Strategy(function(username, password, cb) { User.findAll({ where: { username: username }, }) .then(user => { user = user[0]; if (!user) { return cb(null, false); } if (!bcrypt.compareSync(password, user.password)) { return cb(null, false); } return cb(null, user); }) .catch(err => { return cb(err); }) }) );
User.find({ email: email }, function(err, users) { if (err) res.json({ success: false, message: 'Login failed!!! ' }); console.log(users); if (users.length > 0) { if (bcrypt.compareSync(password, users[0].password)) { var token = jwt.sign({ id: users[0].id }, config.secret); res.json({ success: true, message: 'Successful login!!!', user: users[0], token: token }); } else { res.status(400).json({ success: false, message: 'Please check username/password' }); } } else { res.status(404).json({ success: false, message: 'User not found' }); } });
userModel.findOne({ email: req.body.email }, function (err, userInfo) { console.log(userInfo); if (err) { next(err); } else { if (bcrypt.compareSync(req.body.password, userInfo.password)) { const token = jwt.sign({ id: userInfo._id }, req.app.get('secretKey'), { expiresIn: '1h' }); res.json({ status: "success", message: "user found!!!", data: { user: userInfo, token: token } }); } else { res.json({ status: "error", message: "Invalid email/password!!!", data: null }); } } });
modelUser.loginUser (req) .then (response => { if (response.length != 0) { if (bcrypt.compareSync (req.body.password, response[0].password)) { const token = jwt.sign ({ id : response[0].id }, secretKey, { expiresIn: '7h' }); form.success (res, 200, {user_id: response[0].id, username: response[0].username, token: token}) } else { form.error (res, 400, "Password Incorrect"); } } else { form.error (res, 400, "User Not Found"); } }) .catch (error => { form.error (res, 400, error) })
login (req, res, next) { let data = req.data; let object = {}; for (let i = 0; i < data.length; ++i) if (data[i] !== undefined) object = data[i]; if (!req.body.password) { return res.json({status: false, data: [], message: 'Password is wrong !'}) } if (bcrypt.compareSync(req.body.password, object.password)) { let token = jwt.sign(object, 'cuong', { expiresIn: '1 days' }); return res.status(200).json({status: true, data: {data: object, token: token}, message: 'LOGIN SUCCESS'}); } return res.status(200).json({status: false, data: [], message: 'LOGIN FAILED'}); }
compareHash(password, hash) { return bcrypt.compareSync(password, hash); }