Created
October 10, 2022 16:04
-
-
Save enten/d10eee945c91d1b40e216a8d8913a07b to your computer and use it in GitHub Desktop.
Original PHP function from WordPress PrivateContent (users_manag.php:930):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original PHP function from WordPress PrivateContent (users_manag.php:930): | |
// | |
// public function encrypt_psw($psw) { | |
// return base64_encode( serialize( array(base64_encode($psw), md5(sha1(10091988*strlen($psw))) ))); | |
// } | |
var Base64 = require('js-base64').Base64; | |
var PHPSer = require('php-serialize'); | |
var crypto = require('crypto'); | |
var md5 = require('md5'); | |
var enc = Base64.encode; | |
var ser = PHPSer.serialize; | |
exports = module.exports = encrypt_psw; | |
var DEFAULT_SALT = exports.DEFAULT_SALT = 10091988; | |
function encrypt_psw(p, salt) { | |
return typeof p === 'string' && enc(ser([enc(p), md5(sha1((salt || DEFAULT_SALT)*p.length))])); | |
} | |
function sha1(str) { | |
return crypto.createHash('sha1').update(''+str, 'utf8').digest('hex'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment