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