Last active
October 4, 2016 21:10
-
-
Save stefan2904/4ee1c9e7e72a1ee0fd293970bc2fea99 to your computer and use it in GitHub Desktop.
Mediawiki -> PasswordFactory.php -> generateRandomPasswordString(), see also https://www.mediawiki.org/wiki/Manual:$wgPasswordPolicy
This file contains hidden or 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
<?php | |
/** | |
* Generate a random string suitable for a password | |
* | |
* @param int $minLength Minimum length of password to generate | |
* @return string | |
*/ | |
public static function generateRandomPasswordString( $minLength = 10 ) { | |
// Decide the final password length based on our min password length, | |
// stopping at a minimum of 10 chars. | |
$length = max( 10, $minLength ); | |
// Multiply by 1.25 to get the number of hex characters we need | |
// Generate random hex chars | |
$hex = MWCryptRand::generateHex( ceil( $length * 1.25 ) ); | |
// Convert from base 16 to base 32 to get a proper password like string | |
return substr( Wikimedia\base_convert( $hex, 16, 32, $length ), -$length ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment