当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript crypto.pbkdf2函数代码示例

本文整理汇总了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'));
  });
}
开发者ID:Jeremy-Doucet,项目名称:DanExample,代码行数:7,代码来源:user.model.ts

示例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)
  });

});
开发者ID:benstelzer,项目名称:admissioncalculator,代码行数:7,代码来源:admin.model.ts

示例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'));
  })
}
开发者ID:andrewwb,项目名称:JeremysTraining,代码行数:7,代码来源:userModel.ts

示例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();
  });
});
开发者ID:UtopianOwl,项目名称:dcproj,代码行数:8,代码来源:user.model.ts

示例5: reject

    return new Promise<Buffer>( (resolve, reject ) => {

      crypto.pbkdf2( password, salt, ITERATIONS, keylen, 'sha256', (err, key) => {

        if ( err )
          reject( err );
        else
          resolve( key );
      } );
    })
开发者ID:cryptographix,项目名称:labs-workshop-secure-web-applications,代码行数:10,代码来源:user-auth.ts

示例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,
        });
    });
});
开发者ID:venki143mca,项目名称:TeamBirthday,代码行数:15,代码来源:login.ts

示例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
        });
    });
});
开发者ID:akazimirov,项目名称:domic,代码行数:15,代码来源:login.ts

示例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
        });
    });
});
开发者ID:BLamy,项目名称:angular2-express-starter,代码行数:15,代码来源:login.ts

示例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;
			});
		});
	});
开发者ID:petschekr,项目名称:Dragonoids-Website,代码行数:45,代码来源:server.ts


注:本文中的crypto.pbkdf2函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。