From ae4983dc16e84216e523878b65b1240705a8ac4c Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Tue, 26 Jul 2005 16:09:00 +0000 Subject: [PATCH] Moved password encryption algorithm to GlobalFunctions.php to make it useable for other parts of the code --- includes/GlobalFunctions.php | 18 ++++++++++++++++++ includes/User.php | 18 ++---------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 5011a01170..a694c96cfe 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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; +} + ?> diff --git a/includes/User.php b/includes/User.php index c4b4e819b3..9022831824 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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 -- 2.20.1