當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript bcrypt.compare函數代碼示例

本文整理匯總了TypeScript中bcrypt.compare函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript compare函數的具體用法?TypeScript compare怎麽用?TypeScript compare使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了compare函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: checkUser

    async function checkUser(req, username, password) {
        const email = username.toLowerCase();

        let [user, isLocked] = await Promise.all([
            PassportProvider.findUserForLogin('email', email),
            PassportProvider.isLockedOut('email', email)
        ]);

        if (isLocked) {
            // do absolutely nothing if locked
            return false;
        }

        // TODO: add audit log

        const checkPassword = user ? user.password : 'THISISNOTVALIDPASSWORD';
        const isValid = await bcrypt.compare(password, checkPassword);

        if (isValid) {
            await PassportProvider.clearUserLockout('email', email);

            return user;
        } else {
            const maxFailTries = parseInt(settings.maxFailTries, 10);
            const maxLockTime = parseInt(settings.maxLockTime, 10);

            await PassportProvider.incrementLockOut('email', email, maxFailTries, function(failedCount) {
                return Math.min(
                    maxLockTime,
                    Math.pow(failedCount - maxFailTries, 2) * 5
                );
            });
            return false;
        }
    }
開發者ID:HallM,項目名稱:poc-fw2,代碼行數:35,代碼來源:configure-local.ts

示例2: checkUser

    async function checkUser(req, username, token) {
        const email = username.toLowerCase();

        let [user, isLocked] = await Promise.all([
            PassportProvider.findUserForToken('email', email),
            PassportProvider.isLockedOut('email', email)
        ]);

        if (isLocked) {
            // do absolutely nothing if locked
            return false;
        }

        const checkToken = user ? user.logintoken : 'THISISNOTVALIDPASSWORD';
        const isValid = await bcrypt.compare(token, checkToken);

        // we don't mess with the lock out with tokens, but we could
        if (!isValid) {
            return false;
        }

        await PassportProvider.alterUser(user, {
            logintoken: null,
            tokenexpire: null
        });

        return user;
    }
開發者ID:HallM,項目名稱:poc-fw2,代碼行數:28,代碼來源:configure-token.ts

示例3: Promise

			var promise = new Promise(function (resolve, reject) {
				var hash = result.rows[0].password_hash; 	
		      	bcrypt.compare(password, hash, function(err, res) {
		      		if (res) resolve(result.rows[0].id);
		      		else reject('Invalid password');
				});
		    });
開發者ID:SleepyPierre,項目名稱:BarHigher_Proto,代碼行數:7,代碼來源:users.ts

示例4: next

 .then(function (user) {
     const title_ = 'Reset password';
     if (req.body['passwdnew'] != req.body['passwdnewr']) {
         return res.render('user_resetpasswd', {
             layout: 'subpage', user, title_,
             'redirecturl': req.body['redirecturl'],
             'failed_message': 'New password doesnot match'
         });
     }
     if (!user) {
         return next({ 'status': 404, 'message': 'user not found' }); }
     compare(req.body['passwdorg'], user['passwd'], (err, result) =>
         (err || (!result)) ? res.render('user_resetpasswd', {
             layout: 'subpage', user, title_,
             'redirecturl': req.body['redirecturl'],
             'failed_message': 'Original password doesnot match'
         }) :
         genSalt(10, function (err, salt) {
             if (err) { return next(err); }
             hash(req.body['passwdnew'], salt, (err, hashed) => (err) ? next(err) :  
                 db().none("UPDATE stakeholder SET passwd = $2 WHERE id = $1",
                     [ req.params['id'], hashed ])
                 .then(() => res.render('user_resetpasswd', {
                     layout: 'subpage', user, title_,
                     'redirecturl': req.body['redirecturl'],
                     'succeeded_message': 'Password modified.'
                 }), (reason) => next(emit500()))
             );
         })
     );
 }, () => next(emit404('user not found')))
開發者ID:secondwtq,項目名稱:expressus,代碼行數:31,代碼來源:user.ts

示例5: function

    }, function (err, user) {
        console.log("user",user);
        if (err) throw err;

        if (!user) {
            res.json({ success: false, message: 'Authentication failed. User not found.' });
        } else if (user) {

            // check if password matches
            bcrypt.compare(req.body.password, user.password, function(err, match) {
                if (err) throw err;        
                if (!match) {
                    res.json({ success: false, message: 'Authentication failed. Wrong password.' });
                } else {

                    // if user is found and password is right
                    // create a token
                    var token = jwt.sign(user, config.JWTSECRET, {
                        expiresIn: config.JWTEXPIRE // expires in 24 hours (minutes)
                    });

                    // return the information including token as JSON
                    res.json({
                        success: true,
                        token: token
                    });
                }
            });


        }

    });
開發者ID:pmcalabrese,項目名稱:Express-Typescript-boilerplate,代碼行數:33,代碼來源:users.ts

示例6: function

 managers.dbManager.userLogin(userId,function(err, results) {
     var loginResult = {};
     if (err) {
         console.log(err);
         res.status(500).send("Error");
     }
     else {
         if(results.length === 0) {
             loginResult['authenticated'] = false;
             res.status(500).send();
         }
         else {
             loginResult = results[0];
             bcrypt.compare(password, loginResult['Password'], function(err, result) {
                 if(result) {
                     loginResult['authenticated'] = true;
                     delete loginResult['Password'];
                     delete loginResult['ServerKey'];
                     res.status(200).send(loginResult);
                 }
                 else
                     res.status(500).send();
             });
         }
     }
 })
開發者ID:MattGauler,項目名稱:support-portal-uat,代碼行數:26,代碼來源:userLogin.ts

示例7: resolve

    return new Promise<boolean>((resolve, reject) => {
      bcrypt.compare(plainText, hashedText, (err, res) => {

        if (err) return reject(err);
        return resolve(res);
      });
    });
開發者ID:chen-framework,項目名稱:chen,代碼行數:7,代碼來源:crypto.ts

示例8: function

userSchema.method('comparePassword', function(password, done) {
  bcrypt.compare(password, this.password, (err, isMatch) => {
    /* istanbul ignore next */
    if (err) return done(err);
    done(null, isMatch);
  });
});
開發者ID:Jeremy-Doucet,項目名稱:Blog-Example-Typescript,代碼行數:7,代碼來源:user.model.ts

示例9: function

 return new Promise<boolean>(( resolve, reject ) => {
     bcrypt.compare( key, this._hashedApiKey, function( err, same: boolean ) {
         if ( err )
             return reject( err );
         else
             return resolve( same );
     } );
 } );
開發者ID:Webinate,項目名稱:modepress,代碼行數:8,代碼來源:comms-controller.ts

示例10: function

UserSchema.methods.comparePassword = function (passw, cb) {
    bcrypt.compare(passw, this.password, function (err, isMatch) {
        if (err) {
            return cb(err);
        }
        cb(null, isMatch);
    });
};
開發者ID:ericmdantas,項目名稱:Gen-App,代碼行數:8,代碼來源:userModel.ts


注:本文中的bcrypt.compare函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。