首页 > 代码库 > [Web Security] Create a hash salt password which can stored in DB
[Web Security] Create a hash salt password which can stored in DB
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 databasecrypto.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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。