本文整理汇总了TypeScript中crypto.pbkdf2函数的典型用法代码示例。如果您正苦于以下问题:TypeScript pbkdf2函数的具体用法?TypeScript pbkdf2怎么用?TypeScript pbkdf2使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pbkdf2函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
userSchema.methods.hashPassword = function(password, cb) {
this.salt = crypto.randomBytes(16).toString('hex');
crypto.pbkdf2(password, this.salt, 1000, 32, function(err, buff) {
if (err) return cb(err);
cb(null, buff.toString('hex'));
});
}
示例2: function
adminSchema.method("comparePassword", function(password: string, done: Function){
crypto.pbkdf2(password, this.salt, 1000, 32, (err,hash) => {
if(err) return done (err);
done(null, hash == this.password)
});
});
示例3: function
userSchema.methods.hashPassword = function(password: string, done: Function){
this.salt = crypto.randomBytes(16).toString('hex');
crypto.pbkdf2(password, this.salt, 1000, 32, (err, hash) => {
if(err) return done(err);
done(null, hash.toString('hex'));
})
}
示例4: function
userSchema.method('hashPassword', function(password: string, done: Function) {
this.salt = crypto.randomBytes(16).toString('hex');
crypto.pbkdf2(new Buffer(password), this.salt, 1000, 32, "sha512", (err, hash) => {
if (err) return done(err);
this.password = hash.toString('hex');
done();
});
});
示例5: reject
return new Promise<Buffer>( (resolve, reject ) => {
crypto.pbkdf2( password, salt, ITERATIONS, keylen, 'sha256', (err, key) => {
if ( err )
reject( err );
else
resolve( key );
} );
})
示例6: Error
loginRouter.post("/signup", (request: Request, response: Response, next: NextFunction) => {
if (!request.body.hasOwnProperty("password")) {
const err = new Error("No password");
return next(err);
}
const salt = randomBytes(128).toString("base64");
pbkdf2(request.body.password, salt, 10000, length, digest, (err: Error, hash: Buffer) => {
response.json({
hashed: hash.toString("hex"),
salt,
});
});
});
示例7: function
loginRouter.post('/signup', function (request: Request, response: Response, next: NextFunction) {
if (!request.body.hasOwnProperty('password')) {
let err = new Error('No password');
return next(err);
}
const salt = randomBytes(128).toString('base64');
pbkdf2(request.body.password, salt, 10000, length, digest, (err: Error, hash: Buffer) => {
response.json({
hashed: hash.toString('hex'),
salt: salt
});
});
});
示例8: function
loginRouter.post("/signup", function (req: Request, res: Response, next) {
if (!req.body.hasOwnProperty("password")) {
let err = new Error("No password");
return next(err);
}
const salt = randomBytes(128).toString("base64");
pbkdf2(req.body.password, salt, 10000, length, function (err, hash) {
res.json({
hashed: hash.toString("hex"),
salt: salt
});
});
});
示例9: function
crypto.pbkdf2(oldpassword, response.locals.user.login.salt, response.locals.user.login.iterations, 32, function(err: Error, hashedPasswordBuffer: Buffer) {
var hashedPassword: string = hashedPasswordBuffer.toString("hex");
if (hashedPassword !== response.locals.user.login.hash) {
response.locals.passwordFail = true;
response.locals.passwordMessage = "Old password is not correct"
}
if (response.locals.passwordFail) {
// Render fail page
response.render("passwordchange", function(err: Error, html: string): void {
if (err) {
console.error(err);
response.send(500, "A Jade error occurred!");
return;
}
response.send(html);
});
return;
}
// Valid password change request
var newSalt: string = crypto.randomBytes(32).toString("hex");
crypto.pbkdf2(password1, newSalt, response.locals.user.login.iterations, 32, function(err: Error, hashedPasswordBuffer: Buffer) {
var hashedPassword: string = hashedPasswordBuffer.toString("hex");
// Update in DB
Collections.Users.update({"username": response.locals.user.username}, {$set: {"login.salt": newSalt, "login.hash": hashedPassword}}, {w:1}, function(err: Error) {
if (err) {
response.locals.passwordFail = true;
response.locals.passwordMessage = "A database error occurred";
console.error(err);
}
else {
response.locals.passwordSuccess = "success";
response.locals.passwordMessage = "Password changed successfully";
}
response.render("passwordchange", function(err: Error, html: string): void {
if (err) {
console.error(err);
response.send(500, "A Jade error occurred!");
return;
}
response.send(html);
});
return;
});
});
});