当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript bcrypt.genSalt函数代码示例

本文整理汇总了TypeScript中bcrypt.genSalt函数的典型用法代码示例。如果您正苦于以下问题:TypeScript genSalt函数的具体用法?TypeScript genSalt怎么用?TypeScript genSalt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了genSalt函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

UserSchema.methods.regenerateJWTSalts = async function (): Promise<any> {
    const salts: Array<string> = await Promise.all([
        bcrypt.genSalt(config.get("security.SALT_LENGTH")),
        bcrypt.genSalt(config.get("security.SALT_LENGTH"))
    ]);
    this.jwtSecrets = {
        access: salts[0],
        refresh: salts[1]
    };
    return this.save();
};
开发者ID:ZulusK,项目名称:Budgetarium,代码行数:11,代码来源:User.ts

示例2: function

userSchema.pre("save", function (next: Function) {
    var user: any = this;

    // only hash the password if it has been modified (or is new)
    if (!user.isModified("password")) {
        return next();
    }

    // generate a salt
    bcrypt.genSalt(SALT_WORK_FACTOR, (err: any, salt: any) => {
        if (err) {
            return next(err);
        }

        // hash the password along with our new salt
        bcrypt.hash(user.password, salt, (err2: any, hash: any) => {
            if (err) {
                return next(err2);
            }

            // override the cleartext password with the hashed one
            user.password = hash;
            next();
        });
    });
});
开发者ID:brechtbilliet,项目名称:WineCellarBackend,代码行数:26,代码来源:UserSchema.ts

示例3: Promise

	return new Promise(function (resolve, reject) {
		bcrypt.genSalt(10, function(err, salt) {
			bcrypt.hash(password, salt, function(err, hash) {
				resolve(hash);
			});
		});
	});
开发者ID:SleepyPierre,项目名称:BarHigher_Proto,代码行数:7,代码来源:users.ts

示例4: function

app.post('/signup', function(req, res) { //User "posts the info to the form"
    
let unhashedpassword = req.body.password;  
    
bcrypt.genSalt(10, function(err, salt) {
    bcrypt.hash(unhashedpassword, salt, function(err, hash) {
        // Store hash in your password DB. 
  let user = new User({   
  username: req.body.username ,    
  email: req.body.email , 
  password: hash
}) 
            // save the user
  user.save(function(err) {
    if (err) throw err;
    console.log('User saved successfully');
    res.json({ success: true });

});
    
    });


    

  });
    
    });
开发者ID:Fabreeze23,项目名称:homevideo,代码行数:28,代码来源:server.ts

示例5: hashPassword

 async hashPassword(password: string) {
   const saltRounds = 10;
   const salt = await bcrypt.genSalt(saltRounds);
   try {
     const hashedPassword = await bcrypt.hash(password, salt);
     this.password = hashedPassword;
   } catch(err) {}
 }
开发者ID:HackrLabs,项目名称:HakrPass,代码行数:8,代码来源:user.ts

示例6: function

userSchema.method('hashPassword', function(password, done) {
    bcrypt.genSalt(10, (err, salt) => {
        if (err) return done (err);
        bcrypt.hash(password, salt, (err, hash) => {
            if (err) return done (err);
            done(null, hash);
        });
    });
});
开发者ID:aurbina83,项目名称:veteranconnect,代码行数:9,代码来源:model.ts

示例7: Promise

 return new Promise((resolve, reject) => {
     bcrypt.genSalt((err, salt) => {
         if (err) {
             return reject(err);
         }
         
         return resolve(salt);
     })
 });
开发者ID:kamilbiela,项目名称:auth360-backend,代码行数:9,代码来源:BCryptPasswordHasher.ts

示例8: function

userSchema.method('hashPassword', function(password, done) {
  bcrypt.genSalt(SALT_ROUNDS, (saltErr, salt) => {
    /* istanbul ignore next */
    if (saltErr) return done(saltErr);
    bcrypt.hash(password, salt, (hashErr, hash) => {
      /* istanbul ignore next */
      if (hashErr) return done(hashErr);
      done(null, hash);
    });
  });
});
开发者ID:Jeremy-Doucet,项目名称:Blog-Example-Typescript,代码行数:11,代码来源:user.model.ts

示例9: genSalt

 (req, res, next) =>
     genSalt(10, function (err, salt) {
         if (err) { return next(err); }
         hash(req.body['passwd'], salt, (err, hashed) => (err) ? next(err)
             :
             db().none("INSERT INTO stakeholder(username, passwd, email, register_time, avatar) VALUES ($1, $2, $3, $4, $5)",
                 [ req.body['username'], hashed, req.body['email'], new Date(), config['blog']['default_avatar'] ])
             .then(() => res.redirect('/user/login'),
                 (reason) => next(reason))
         );
     })
开发者ID:secondwtq,项目名称:expressus,代码行数:11,代码来源:user.ts

示例10: resolve

    return new Promise<string>((resolve, reject) => {
      bcrypt.genSalt(saltLength, (err, salt) => {

        if (err) return reject(err);
        bcrypt.hash(text, salt, (error, hash) => {

          if (error) return reject(error);
          return resolve(hash);
        });
      });
    });
开发者ID:chen-framework,项目名称:chen,代码行数:11,代码来源:crypto.ts


注:本文中的bcrypt.genSalt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。