committing Hendrik Brummermann's checkPassword() patch, plus some modifications to...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 30 Jul 2004 11:13:54 +0000 (11:13 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 30 Jul 2004 11:13:54 +0000 (11:13 +0000)
includes/SpecialPreferences.php
includes/SpecialUserlogin.php
includes/User.php

index 37ec594..6f6e75b 100644 (file)
@@ -134,12 +134,10 @@ class PreferencesForm {
                                $this->mainPrefsForm( wfMsg( "badretype" ) );                   
                                return;
                        }
-                       $ep = $wgUser->encryptPassword( $this->mOldpass );
-                       if ( $ep != $wgUser->getPassword() ) {
-                               if ( $ep != $wgUser->getNewpassword() ) {
-                                       $this->mainPrefsForm( wfMsg( "wrongpassword" ) );
-                                       return;
-                               }
+
+                       if (!$wgUser->checkPassword( $this->mOldpass )) {
+                               $this->mainPrefsForm( wfMsg( "wrongpassword" ) );
+                               return;
                        }
                        $wgUser->setPassword( $this->mNewpass );
                }
index 5c68b84..f69fc8b 100644 (file)
@@ -201,12 +201,9 @@ class LoginForm {
                }
                $u->setId( $id );
                $u->loadFromDatabase();
-               $ep = $u->encryptPassword( $this->mPassword );
-               if ( 0 != strcmp( $ep, $u->getPassword() ) ) {
-                       if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) {
-                               $this->mainLoginForm( wfMsg( "wrongpassword" ) );
-                               return;
-                       }
+               if (!$u->checkPassword( $this->mPassword )) {
+                       $this->mainLoginForm( wfMsg( "wrongpassword" ) );
+                       return;
                }
 
                # We've verified now, update the real record
index f31c81b..7d10777 100644 (file)
@@ -319,16 +319,6 @@ class User {
                return ($timestamp >= $this->mTouched);
        }
 
-       function getPassword() {
-               $this->loadFromDatabase();
-               return $this->mPassword;
-       }
-
-       function getNewpassword() {
-               $this->loadFromDatabase();
-               return $this->mNewpassword;
-       }
-
        function addSalt( $p ) {
                global $wgPasswordSalt;
                if($wgPasswordSalt)
@@ -721,6 +711,26 @@ class User {
        function isNewbie() {
                return $this->mId > User::getMaxID() * 0.99 && !$this->isSysop() && !$this->isBot() || $this->getID() == 0;
        }
+       
+       # Check to see if the given clear-text password is one of the accepted passwords
+       function checkPassword( $password ) {
+               print "hello\n";
+               $this->loadFromDatabase();
+               $ep = $this->encryptPassword( $password );
+               if ( 0 == strcmp( $ep, $this->mPassword ) ) {
+                       return true;
+               } elseif ( 0 == strcmp( $ep, $this->mNewpassword ) ) {
+                       return true;
+               } elseif ( function_exists( 'iconv' ) ) {
+                       # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
+                       # Check for this with iconv
+/*                     $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
+                       if ( 0 == strcmp( $cp1252hash, $this->mPassword ) ) {
+                               return true;
+                       }*/
+               }
+               return false;
+       }
 }
 
 ?>