From 022265211b1a3b3dad3fcf679756392c3eb6a285 Mon Sep 17 00:00:00 2001 From: "justdave%syndicomm.com" <> Date: Wed, 11 Jul 2001 12:29:16 +0000 Subject: Fix for bug 77473, bug 74032, and bug 85472: Passwords are no longer stored in plaintext in the database. Passwords are no longer encrypted with MySQL's ENCRYPT() function (because it doesn't work on some installs), but with Perl's crypt() function. The crypt-related routines now properly deal with salts so that they work on systems that use methods other than UNIX crypt to crypt the passwords (such as MD5). Checksetup.pl will walk through your database and re-crypt everyone's passwords based on the plaintext password entry, then drop the plaintext password column. As a consequence of no longer having a plaintext password, it is no longer possible to email someone their password, so the login screen has been changed to request a password reset instead. The user is emailed a temporary identifying token, with a link back to Bugzilla. They click on the link or paste it into their browser and Bugzilla allows them to change their password. Patch by Myk Melez r= justdave@syndicomm.com, jake@acutex.net --- editusers.cgi | 64 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) (limited to 'editusers.cgi') diff --git a/editusers.cgi b/editusers.cgi index 41240473e..48dcfa0c1 100755 --- a/editusers.cgi +++ b/editusers.cgi @@ -97,10 +97,9 @@ sub EmitElement ($$) # Displays the form to edit a user parameters # -sub EmitFormElements ($$$$$$) +sub EmitFormElements ($$$$$) { - my ($user, $password, $realname, $groupset, $blessgroupset, - $disabledtext) = @_; + my ($user, $realname, $groupset, $blessgroupset, $disabledtext) = @_; print " Login name:\n"; EmitElement("user", $user); @@ -115,7 +114,11 @@ sub EmitFormElements ($$$$$$) if(Param('useLDAP')) { print " This site is using LDAP for authentication!\n"; } else { - print " \n"; + print qq| +
+ (enter new password to change) + + |; } print "\n"; @@ -386,7 +389,7 @@ if ($action eq 'add') { print "
\n"; print "\n"; - EmitFormElements('', '', '', 0, 0, ''); + EmitFormElements('', '', 0, 0, ''); print "
\n
\n"; print "\n"; @@ -423,7 +426,10 @@ if ($action eq 'new') { # Cleanups and valididy checks my $realname = trim($::FORM{realname} || ''); - my $password = trim($::FORM{password} || ''); + # We don't trim the password since that could falsely lead the user + # to believe a password with a space was accepted even though a space + # is an illegal character in a Bugzilla password. + my $password = $::FORM{'password'}; my $disabledtext = trim($::FORM{disabledtext} || ''); my $emailregexp = Param("emailregexp"); @@ -445,10 +451,9 @@ if ($action eq 'new') { PutTrailer($localtrailer); exit; } - if ($password !~ /^[a-zA-Z0-9-_]*$/ || length($password) < 3 || length($password) > 16) { - print "The new user must have a password. The password must be between ", - "3 and 16 characters long and must contain only numbers, letters, ", - "hyphens and underlines. Press Back and try again.\n"; + my $passworderror = ValidatePassword($password); + if ( $passworderror ) { + print $passworderror; PutTrailer($localtrailer); exit; } @@ -473,12 +478,11 @@ if ($action eq 'new') { # Add the new user SendSQL("INSERT INTO profiles ( " . - "login_name, password, cryptpassword, realname, groupset, " . + "login_name, cryptpassword, realname, groupset, " . "disabledtext" . " ) VALUES ( " . SqlQuote($user) . "," . - SqlQuote($password) . "," . - "encrypt(" . SqlQuote($password) . ")," . + SqlQuote(Crypt($password)) . "," . SqlQuote($realname) . "," . $bits . "," . SqlQuote($disabledtext) . ")" ); @@ -682,24 +686,20 @@ if ($action eq 'edit') { CheckUser($user); # get data of user - SendSQL("SELECT password, realname, groupset, blessgroupset, disabledtext + SendSQL("SELECT realname, groupset, blessgroupset, disabledtext FROM profiles WHERE login_name=" . SqlQuote($user)); - my ($password, $realname, $groupset, $blessgroupset, + my ($realname, $groupset, $blessgroupset, $disabledtext) = FetchSQLData(); print "\n"; print "\n"; - EmitFormElements($user, $password, $realname, $groupset, $blessgroupset, - $disabledtext); + EmitFormElements($user, $realname, $groupset, $blessgroupset, $disabledtext); print "
\n"; print "\n"; - if ($editall && !Param('useLDAP')) { - print "\n"; - } print "\n"; print "\n"; print "\n"; @@ -726,8 +726,7 @@ if ($action eq 'update') { my $userold = trim($::FORM{userold} || ''); my $realname = trim($::FORM{realname} || ''); my $realnameold = trim($::FORM{realnameold} || ''); - my $password = trim($::FORM{password} || ''); - my $passwordold = trim($::FORM{passwordold} || ''); + my $password = $::FORM{password} || ''; my $disabledtext = trim($::FORM{disabledtext} || ''); my $disabledtextold = trim($::FORM{disabledtextold} || ''); my $groupsetold = trim($::FORM{groupsetold} || '0'); @@ -791,14 +790,19 @@ if ($action eq 'update') { print "Updated ability to tweak permissions of other users.\n"; } - if(!Param('useLDAP')) { - if ($editall && $password ne $passwordold) { - my $q = SqlQuote($password); - SendSQL("UPDATE profiles - SET password= $q, cryptpassword = ENCRYPT($q) - WHERE login_name=" . SqlQuote($userold)); - print "Updated password.
\n"; - } + # Update the database with the user's new password if they changed it. + if ( !Param('useLDAP') && $editall && $password ) { + my $passworderror = ValidatePassword($password); + if ( !$passworderror ) { + my $cryptpassword = SqlQuote(Crypt($password)); + my $loginname = SqlQuote($userold); + SendSQL("UPDATE profiles + SET cryptpassword = $cryptpassword + WHERE login_name = $loginname"); + print "Updated password.
\n"; + } else { + print "Did not update password: $passworderror
\n"; + } } if ($editall && $realname ne $realnameold) { SendSQL("UPDATE profiles -- cgit v1.2.3-24-g4f1b