Skip to content

Instantly share code, notes, and snippets.

@enten
Created October 10, 2022 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enten/d10eee945c91d1b40e216a8d8913a07b to your computer and use it in GitHub Desktop.
Save enten/d10eee945c91d1b40e216a8d8913a07b to your computer and use it in GitHub Desktop.
Original PHP function from WordPress PrivateContent (users_manag.php:930):
// 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