Guest User

Untitled

a guest
Jun 10th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is a port of sql/password.c:hash_password which needs to be used for
  2. // pre-4.1 passwords.
  3. exports.hashPassword = function(password) {
  4.   var nr = 1345345333,
  5.       add = 7,
  6.       nr2 = 0x12345671,
  7.       result = new Buffer(8);
  8.  
  9.   password = new Buffer(password);
  10.   for (var i = 0; i < password.length; i++) {
  11.     var c = password[i];
  12.     if (c == 32 || c == 9) {
  13.       // skip space in password
  14.       continue;
  15.     }
  16.  
  17.     nr ^= this.multiply(((nr & 63) + add), c) + (nr << 8);
  18.     nr2 += (nr << 8) ^ nr;
  19.     add += c;
  20.   }
  21.  
  22.   this.int32Write(result, nr & ((1 << 31) - 1), 0);
  23.   this.int32Write(result, nr2 & ((1 << 31) - 1), 4);
  24.  
  25.   return result;
  26. }
  27.  
  28. exports.multiply = function(x, y) {
  29.   var lowX = x & 0xffff,
  30.       highX = (x >> 16) & 0xffff,
  31.       lowY = y & 0xffff,
  32.       highY = (y >> 16) & 0xffff
  33.       result =
  34.         0x10000 * ((highX * lowY + lowX * highY) & 0xffff) + lowY * lowX;
  35.  
  36.   //result = result & 0xffffffff;
  37.   result = result % 0x100000000;
  38.   return result;
  39. }
  40.  
  41. exports.int32Write = function(buffer, number, offset) {
  42.   var unsigned = (number < 0) ? (number + 0x100000000) : number;
  43.   buffer[offset] = Math.floor(unsigned / 0xffffff);
  44.   unsigned &= 0xffffff;
  45.   buffer[offset + 1] = Math.floor(unsigned / 0xffff);
  46.   unsigned &= 0xffff;
  47.   buffer[offset + 2] = Math.floor(unsigned / 0xff);
  48.   unsigned &= 0xff;
  49.   buffer[offset + 3] = Math.floor(unsigned);
  50. };
Advertisement
Add Comment
Please, Sign In to add comment