Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a port of sql/password.c:hash_password which needs to be used for
- // pre-4.1 passwords.
- exports.hashPassword = function(password) {
- var nr = 1345345333,
- add = 7,
- nr2 = 0x12345671,
- result = new Buffer(8);
- password = new Buffer(password);
- for (var i = 0; i < password.length; i++) {
- var c = password[i];
- if (c == 32 || c == 9) {
- // skip space in password
- continue;
- }
- nr ^= this.multiply(((nr & 63) + add), c) + (nr << 8);
- nr2 += (nr << 8) ^ nr;
- add += c;
- }
- this.int32Write(result, nr & ((1 << 31) - 1), 0);
- this.int32Write(result, nr2 & ((1 << 31) - 1), 4);
- return result;
- }
- exports.multiply = function(x, y) {
- var lowX = x & 0xffff,
- highX = (x >> 16) & 0xffff,
- lowY = y & 0xffff,
- highY = (y >> 16) & 0xffff
- result =
- 0x10000 * ((highX * lowY + lowX * highY) & 0xffff) + lowY * lowX;
- //result = result & 0xffffffff;
- result = result % 0x100000000;
- return result;
- }
- exports.int32Write = function(buffer, number, offset) {
- var unsigned = (number < 0) ? (number + 0x100000000) : number;
- buffer[offset] = Math.floor(unsigned / 0xffffff);
- unsigned &= 0xffffff;
- buffer[offset + 1] = Math.floor(unsigned / 0xffff);
- unsigned &= 0xffff;
- buffer[offset + 2] = Math.floor(unsigned / 0xff);
- unsigned &= 0xff;
- buffer[offset + 3] = Math.floor(unsigned);
- };
Advertisement
Add Comment
Please, Sign In to add comment