本文整理匯總了TypeScript中bcrypt-nodejs.genSaltSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript genSaltSync函數的具體用法?TypeScript genSaltSync怎麽用?TypeScript genSaltSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了genSaltSync函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: init
export function init(sequelize, DataTypes) {
let fields = {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
email: {
type: DataTypes.STRING
},
profile: {
type: DataTypes.JSON //local, google, facebook
}
};
let options = {
classMethods: {
generateHash(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
},
},
instanceMethods: {
getFullName() {
return `${this.lastName}, ${this.firstName}`;
}
}
};
let model = helper.defineModel('user', fields, options, sequelize);
return model;
}
示例2: AddPasswordSync
AddPasswordSync(password: string): void {
if (password) {
let it = this;
let round = (Math.floor(Math.random() * 10) + 1);
Log.d("User", "AddPasswordSync", "Generating SaltSync", round);
let salt = bcript.genSaltSync(round);
Log.d("User", "AddPasswordSync", "Generating HashSync", salt);
let hash = bcript.hashSync(password, salt);
Log.d("User", "AddPasswordSync", "password encrypted", hash);
it.Password = hash;
}
}
示例3: setPasswordFn
setPassword: function setPasswordFn(password: string) {
const self: IUserInstance = this;
if (!password) {
throw new Error('Password Can\'t Be Null!');
}
const salt = bcrypt.genSaltSync();
const encrypted = bcrypt.hashSync(password, salt);
self.setDataValue('password', encrypted);
return self.save();
},
示例4: function
ConsumerSchema.pre('save', function(next: Function): void {
let user = this
if (user.isModified('password')) {
// generate a salt then run callback
let salt = bcrypt.genSaltSync(CONFIG.USER_SALT_LENGTH)
user.password = bcrypt.hashSync(user.password, salt)
user.updated = UTIL.getTimestamp()
}
if (user.isNew) {
user.wasNew = user.isNew
}
next()
})
示例5: generateHash
userSchema.methods.generateHash = function generateHash(password: string): string {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
}
示例6: function
encrypt: function(value: string) {
var salt = bcrypt.genSaltSync(parseInt(process.env.BCRYPT_SALT));
return bcrypt.hashSync(value, salt);
},
示例7: bcryptHash
public static bcryptHash(data: string): string {
let salt = bcrypt.genSaltSync(10);
return bcrypt.hashSync(data, salt);
}
示例8: function
userSchema.methods.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};
示例9: generateHash
export function generateHash(noHashedString: string) {
return bcrypt.hashSync(noHashedString, bcrypt.genSaltSync(8));
}