From a0f70f4f02939d9a58ffd0788e1b2fad5ed1db96 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 1 Dec 2005 08:15:08 +0000 Subject: [PATCH] * (bug 4071) Generate passwords long enough for $wgMinimalPasswordLength Patch by Sven Klemm, http://bugzilla.wikimedia.org/attachment.cgi?id=1104&action=view --- RELEASE-NOTES | 1 + includes/User.php | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index d09fd1c97b..40e5509cd2 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -265,6 +265,7 @@ fully support the editing toolbar, but was found to be too confusing. * (bug 3922) Further tweaks to bidi overrides in category list for old versions of Safari and Konqueror * Don't die() when update.php reaches the end of the warning count +* (bug 4071) Generate passwords long enough for $wgMinimalPasswordLength === Caveats === diff --git a/includes/User.php b/includes/User.php index 551aa23c36..144c7832c1 100644 --- a/includes/User.php +++ b/includes/User.php @@ -268,13 +268,16 @@ class User { * @todo Check what is doing really [AV] */ function randomPassword() { + global $wgMinimalPasswordLength; $pwchars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz'; $l = strlen( $pwchars ) - 1; - $np = $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} . - $pwchars{mt_rand( 0, $l )} . chr( mt_rand(48, 57) ) . - $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} . - $pwchars{mt_rand( 0, $l )}; + $pwlength = max( 7, $wgMinimalPasswordLength ); + $digit = mt_rand(0, $pwlength - 1); + $np = ''; + for ( $i = 0; $i < $pwlength; $i++ ) { + $np .= $i == $digit ? chr( mt_rand(48, 57) ) : $pwchars{ mt_rand(0, $l)}; + } return $np; } -- 2.20.1