Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var crypto = require('crypto');
- module.exports = {
- algorithm: 'sha256',
- repetitions: 65536,
- generateHash: function(value){
- var v = crypto.createHash(this.algorithm);
- v.update(value);
- return v.digest();
- },
- checkPassword: function(password, input){
- return password === this.hashPassword(input, password.substr(0, password.length/2));
- },
- hashPassword: function(password, salt){
- var repetitions = this.repetitions;
- salt = salt || this.generateHash(crypto.randomBytes(16));
- hash = this.generateHash (salt + password);
- while (repetitions--)
- hash = this.generateHash(hash + repetitions + salt + password);
- return salt + hash;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement