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


TypeScript bcrypt.compareSync函數代碼示例

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


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

示例1:

 .then(user => {
     if (bcrypt.compareSync(password, user.password)) {
         return UserModel.fromEntity(user);
     } else {
         return null;
     }
 });
開發者ID:mowgliLab,項目名稱:baguette-garnie,代碼行數:7,代碼來源:user.bl.ts

示例2: reject

			.then((accountOrganizationMember: AccountOrganizationMember) => {
				
				if (!bcrypt.compareSync(data.password, ObjectUtil.getStringUnionProperty(accountOrganizationMember.user, 'password'))) {
					return reject(new Error('Invalid password'));
				}
				resolve(accountOrganizationMember.user);
			})
開發者ID:jnamla,項目名稱:herokuTestCymplar,代碼行數:7,代碼來源:login_service.ts

示例3: reject

			.then((user: User) => {
				if (ObjectUtil.isBlank(user)) {
					return reject(new Error('The user does not exist within this organization'));
				}
				if (!bcrypt.compareSync(data.password, user.password)) {
					return reject(new Error('Invalid password'));
				}
				resolve(user);
			})
開發者ID:australdev,項目名稱:app,代碼行數:9,代碼來源:login_service.ts

示例4: authSuccess

 authSuccess(res:Response, credentials: any, data:any){
     const isMatch = bcrypt.compareSync(credentials.password, data.password);
 
     if(isMatch){
         const payload = {
             id: data.id
         }
 
         res.json({
             token : jwt.encode(payload, config.secret)
         });
     }
     else{
         res.sendStatus(httpStatus.UNAUTHORIZED);
     }
 }
開發者ID:mromanjr93,項目名稱:nodejsddd,代碼行數:16,代碼來源:handlers.ts

示例5: function

updateRecord = async function(id,data, model){
    let
    user,
    res;

    try {
        user = await model.$findById('id', id, [1]);
    } catch(err) {
        return Promise.reject(err);
    }

    try {
        res  = await bcrypt.compareSync(`|-:${data.oldpwd}:-|`, user.password);

        if(!res)
            return errors.error({
                code  : '104'
            });

        let
        _salt = bcrypt.genSaltSync(12),
        _pwd  = bcrypt.hashSync(`|-:${data.newpwd}:-|`, _salt);

        /** TODO 此處用以下方式更新 password 會提示:
            ValidationError: user validation failed

            user.password = _pwd;
            user = await user.save();
        */

        let
        update = await model.update({
            _id : user._id
        }, {
            $set : {
                password : _pwd
            }
        }).exec();

        return update.ok === 1 ? errors.success(true) : errors.error({
            code : '31'
        });
    } catch(err) {
        return Promise.reject(err);
    }

};
開發者ID:goumang2010,項目名稱:NetTxtNote,代碼行數:47,代碼來源:static.resetPassword.ts

示例6:

    User.findOne({name: req.body.name}).exec().then((user: UserModelInterface) => {
      if (!(user && bcrypt.compareSync(req.body.password, user.password))) {
        return Promise.resolve(res.json(message));
      }

      // creates the jwt toke with a 6 hours duration
      // since jwt typing states sign returns void, we have
      // to assert the return as any (string doesn't work)
      let token = jwt.sign({name: user.name}, app.get('jwtSecret'), {
        expiresIn: '6h'
      }) as any;

      let response: Comprobable = {success: true, token: token};

      // returns the token with a success message
      return Promise.resolve(res.json(response));
    }, err => {
開發者ID:slayerfat,項目名稱:deployer,代碼行數:17,代碼來源:login.route.ts

示例7: moment

                cursor.next((err, row) => {
                    if (err && err.message.indexOf('No more rows in the cursor') > -1) {
                        res.status(404).end('User does not exist.');
                    } else {
                        const valid = bcrypt.compareSync(req.body.password, row.password);
                        if (valid) {
                            const exp = moment().add(3, "months").valueOf();
                            const user = {
                                userId: row.id, email: row.email, expires: exp, refresh_token: row.refresh_token, access_token: jwtoken.sign({ isAdmin: row.isAdmin }, config.SECRET, { issuer: row.id, expiresIn: exp })
                            };
                            res.set('Content-Type', 'application/json');
                            res.json(user);
                        } else if (!valid) {
                            res.status(500).end('The password you entered is incorrect')
                        }

                    }
                })
開發者ID:triniwiz,項目名稱:mojichat-api,代碼行數:18,代碼來源:users.ts

示例8: function

createRecord = async function(data, model){
    try{
        let
        res = await model.findOne({
            name : data.name
        }).where('_status').equals(1).select('password');

        if(!res){
            return errors.error({
                code  : '214'
            });
        }

        res = await bcrypt.compareSync(`|-:${data.password}:-|`, res.password);

        return res ? errors.success(res) : errors.error({
            code  : '214'
        });
    }catch(err){
        return errors.format(err);
    }
};
開發者ID:goumang2010,項目名稱:NetTxtNote,代碼行數:22,代碼來源:static.validatePassword.ts

示例9: function

UserSchema.method("verifyPassword", function(password: string) {
  return bcrypt.compareSync(password, this.local.password);
});
開發者ID:snyderjk,項目名稱:TheCodeJo,代碼行數:3,代碼來源:user.ts

示例10: validateUserPassword

 static validateUserPassword(password: string, encryptedPassword: string): boolean {
   return bcrypt.compareSync(password, encryptedPassword);
 }
開發者ID:KShewengerz,項目名稱:ngx-express-passport-setup,代碼行數:3,代碼來源:Account.ts


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