我有下面的代码。我正在尝试在注册时对我的管理员密码进行哈希处理。最初通过猫鼬模式将密码设置为默认值。以下是我的代码。但这不是散列。
AdminSchema.pre('save', function(next){
let admin = this; // bind this
if(admin.$isDefault('password')) {
bcrypt.genSalt(12, (err, salt)=> { // generate salt and harsh password
bcrypt.hash(admin.password, salt, (err, hash)=> {
admin.password = hash;
return next();
});
});
}
if(!admin.isModified('password')) {
return next();
}
bcrypt.genSalt(12, (err, salt)=> { // generate salt and harsh password
bcrypt.hash(admin.password, salt, (err, hash)=> {
admin.password = hash;
next();
});
});
});
答案 0 :(得分:1)
这是因为bcrypt方法是异步执行的,因此第一次将始终执行
optimize
这应该有效
julia> f(x::Vector{Float64}) = x
f (generic function with 1 method)
julia> f([1,2,3])
ERROR: MethodError: no method matching f(::Array{Int64,1})
Closest candidates are:
f(::Array{Float64,1}) at REPL[9]:1
Stacktrace:
[1] top-level scope at none:0