当前位置: 首页>>代码示例>>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;未经允许,请勿转载。