當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。