Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { promisify } = require('util');
  2. const { randomBytes, pbkdf2 } = require('crypto');
  3.  
  4. const generateRandomBytes = promisify(randomBytes);
  5. const hashPassword = promisify(pbkdf2);
  6.  
  7. const _ = {
  8.  async hashPassword(args){
  9.  const { pw } = args;
  10.  const salt = (args.salt || await generateRandomBytes(64)).toString('hex');
  11.  const iter = (args.iter || await this.generateRandomInt(1024)) + 10000;
  12.  
  13.  const hash = await hashPassword(pw, salt, iter, 64, 'sha512').toString('hex');
  14.  return `${hash}:${salt}:${iter}`;
  15.     }
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement