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


TypeScript bcrypt-nodejs.genSalt函數代碼示例

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


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

示例1: it

 it('Testing genSalt', function(done) {
     theSalt = bcrypt.genSalt(10, (err, salt) => {
         theSalt = salt;
         expect(err).to.equal(null);
         done();
     });
 });
開發者ID:GeekAthelon,項目名稱:SoiWidgets,代碼行數:7,代碼來源:bcrypt-nodejs-mocha.ts

示例2: function

PlatformSchema.pre('save', function(next: Function): void {
  let user = this

  // generate a salt then run callback
  if (user.isNew) {
    bcrypt
    .genSalt(10, (err: Error, salt: string) => {
      if (err) { return next(err) }

      // encrypt password with salt
      bcrypt.hash(user.password, salt, null, (err, hash) => {
        if (err) { return next(err) }

        // overwrite plain text password with encrypted password
        user.password = hash

        next()
      })
    })
  } else {
    UTIL.setUpdateTime(user, ['username', 'password', 'nickname', 'name', 'gender', 'mobile', 'email', 'pid', 'avatar', 'background', 'locale', 'city', 'country'])
    user.wasNew = user.isNew

    next()
  }
})
開發者ID:yeegr,項目名稱:SingularJS,代碼行數:26,代碼來源:PlatformModel.ts

示例3: reject

 return new Promise<string>((resolve, reject) => {
     bcrypt.genSalt(-1, (err, salt) => {
         /* istanbul ignore if */
         if (err) {
             reject(err);
         }
         resolve(salt);
     });
 });
開發者ID:GeekAthelon,項目名稱:SoiWidgets,代碼行數:9,代碼來源:password-hash-bcrypt.ts

示例4: save

userSchema.pre("save", function save(next) {
  const user = this;
  if (!user.isModified("password")) { return next(); }
  bcrypt.genSalt(10, (err, salt) => {
    if (err) { return next(err); }
    bcrypt.hash(user.password, salt, undefined, (err: mongoose.Error, hash) => {
      if (err) { return next(err); }
      user.password = hash;
      next();
    });
  });
});
開發者ID:omnajjar,項目名稱:node-express-app-starter,代碼行數:12,代碼來源:User.ts

示例5: function

userSchema.pre("save", function(done) {
  var user = this;

  if (!user.isModified("password")) {
    return done();
  }

  bcrypt.genSalt(SALT_FACTOR, function(err, salt) {
    if (err) { return done(err); }
    bcrypt.hash(user.password, salt, noop, function(err, hashedPassword) {
      if (err) { return done(err); }
      user.password = hashedPassword;
      done();
    });
  });
});
開發者ID:Muhammmad-Zubaid,項目名稱:learn-typed-express,代碼行數:16,代碼來源:user.ts

示例6: getPasswordHash

function getPasswordHash(password: string): Promise<string> {
    var resolve, reject;
    var promise = new Promise<string>((res, rej) => {
        resolve = res;
        reject = rej;
    });

    var createHash = (saltError, salt) => {
        if (saltError) return reject("Failed to create salt: " + saltError);
        bcrypt.hash(password, salt, null, (err, hash) => {
            if (err) return reject("Failed to create hash: " + err);
            resolve(hash);
        });
    }

    var salt = bcrypt.genSalt(10, createHash);
    return promise;
}
開發者ID:Seikho,項目名稱:auth-api,代碼行數:18,代碼來源:createHash.ts

示例7: function

_schema.pre('save', function(next) {
    let account: IAccount = this;
    if (!account.isModified()) {
        return next();
    }
    if (account.password === '') {
        if (!account.activationToken) {
            console.log('no password no activationToken');
            return next();
        }
    }
    bcrypt.genSalt(1000, (err, salt) => {
        if (err) {
            return next(err);
        }
        bcrypt.hash(account.password, salt, ()=>{} ,(err, hash) => {
            if (err) {
                return next(err);
            }
            account.password = hash;
            next();
        })
    })
})
開發者ID:DavidOnGitHub,項目名稱:questionApp_backend,代碼行數:24,代碼來源:Account.ts

示例8: AddPassword

 AddPassword(password: string, callback: () => void): void {
     if (!password) {
         throw new Error("password doesn't contain value");
     }
     let it = this;
     let round = (Math.floor(Math.random() * 10) + 1);
     Log.d("User", "AddPassword", "Generating Salt", round);
     bcript.genSalt(round, (error: Error, salt: string): void => {
         if (error) {
             Log.c("User", "AddPassword", "bcript.genSalt", error);
             throw error;
         }
         Log.d("User", "Generating Hash", salt);
         bcript.hash(password, salt, DataModel.User.encryptingProgress, (error: Error, hash: string): void => {
             if (error) {
                 Log.c("User", "AddPassword", "bcript.hash", error);
                 throw error;
             }
             Log.d("User", "AddPassword", "password encrypted", hash);
             it.Password = hash;
             callback();
         });
     });
 }
開發者ID:pteyssedre,項目名稱:lazy-uac,代碼行數:24,代碼來源:models.ts

示例9: Promise

 return new Promise(function(resolve, reject) {
   bcrypt.genSalt(rounds, function(err, salt) {
     if (err) return reject(err);
     return resolve(salt);
   });
 });
開發者ID:girishgupta211,項目名稱:LAAS_Server,代碼行數:6,代碼來源:bcrypt_thunk.ts


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