Moved password encryption algorithm to GlobalFunctions.php to make it useable for...
authorJens Frank <jeluf@users.mediawiki.org>
Tue, 26 Jul 2005 16:09:00 +0000 (16:09 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Tue, 26 Jul 2005 16:09:00 +0000 (16:09 +0000)
includes/GlobalFunctions.php
includes/User.php

index 5011a01..a694c96 100644 (file)
@@ -1286,4 +1286,22 @@ function wfPercent( $nr, $acc = 2, $round = true ) {
        $ret = sprintf( "%.${acc}f", $nr );
        return $round ? round( $ret, $acc ) . '%' : "$ret%";
 }
+
+/**
+ * Encrypt a username/password.
+ *
+ * @param string $userid ID of the user
+ * @param string $password Password of the user
+ * @return string Hashed password
+ */
+function wfEncryptPassword( $userid, $password ) {
+       global $wgPasswordSalt;
+       $p = md5( $password);
+
+       if($wgPasswordSalt)
+               return md5( "{$userid}-{$p}" );
+       else
+               return $p;
+}
+
 ?>
index c4b4e81..9022831 100644 (file)
@@ -802,28 +802,14 @@ class User {
                return ($timestamp >= $this->mTouched);
        }
 
-       /**
-        * Salt a password.
-        * Will only be salted if $wgPasswordSalt is true
-        * @param string Password.
-        * @return string Salted password or clear password.
-        */
-       function addSalt( $p ) {
-               global $wgPasswordSalt;
-               if($wgPasswordSalt)
-                       return md5( "{$this->mId}-{$p}" );
-               else
-                       return $p;
-       }
-
        /**
         * Encrypt a password.
         * It can eventuall salt a password @see User::addSalt()
         * @param string $p clear Password.
-        * @param string Encrypted password.
+        * @return string Encrypted password.
         */
        function encryptPassword( $p ) {
-               return $this->addSalt( md5( $p ) );
+               return wfEncryptPassword( $this->mId, $p );
        }
 
        # Set the password and reset the random token