码迷,mamicode.com
首页 > 数据库 > 详细

[Web Security] Create a hash salt password which can stored in DB

时间:2017-08-09 21:13:39      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:this   and   base   SHA256   cti   anti   har   for   com   

We cannot directly store user password in the database. 

What need to do is creating a hashed & salted string which reperstanting the user password. 

This password is not reverable. And very hard for hacker to guess what is the origial password by using Dictionary Attacks.

 

var crypto = require(crypto);


var password = "monkey";

// randomBytes: generate a salt pre user, salt should be stored with hashed password in the database
crypto.randomBytes(256, function(err, salt) {

  // pbkdf2: combine the salt the hash password algorithm, to generate a safe password
  crypto.pbkdf2(password, salt, 100000, 512, sha256,
    function(err, hash) {

      console.log("The result of hashing " + password + " is:\n\n" +
        hash.toString(hex) + "\n\n");

    });


});

 

[Web Security] Create a hash salt password which can stored in DB

标签:this   and   base   SHA256   cti   anti   har   for   com   

原文地址:http://www.cnblogs.com/Answer1215/p/7327513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!