r44815 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44814‎ | r44815 | r44816 >
Date:23:18, 19 December 2008
Author:skizzerz
Status:ok
Tags:
Comment:
* adding two hooks UserCryptPassword and UserComparePasswords to allow extensions to change how passwords are hashed in the database
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1328,9 +1328,21 @@
13291329 'UserClearNewTalkNotification': called when clearing the "You have new messages!" message, return false to not delete it
13301330 $user: User (object) that'll clear the message
13311331
 1332+'UserComparePasswords': called when checking passwords, return false to override the default password checks
 1333+&$hash: String of the password hash (from the database)
 1334+&$password: String of the plaintext password the user entered
 1335+&$userId: Integer of the user's ID or Boolean false if the user ID was not supplied
 1336+&$result: If the hook returns false, this Boolean value will be checked to determine if the password was valid
 1337+
13321338 'UserCreateForm': change to manipulate the login form
13331339 $template: SimpleTemplate instance for the form
13341340
 1341+'UserCryptPassword': called when hashing a password, return false to implement your own hashing method
 1342+&$password: String of the plaintext password to encrypt
 1343+&$salt: String of the password salt or Boolean false if no salt is provided
 1344+&$wgPasswordSalt: Boolean of whether the salt is used in the default hashing method
 1345+&$hash: If the hook returns false, this String will be used as the hash
 1346+
13351347 'UserEffectiveGroups': Called in User::getEffectiveGroups()
13361348 $user: User to get groups for
13371349 &$groups: Current effective groups
Index: trunk/phase3/includes/User.php
@@ -3249,6 +3249,11 @@
32503250 static function crypt( $password, $salt = false ) {
32513251 global $wgPasswordSalt;
32523252
 3253+ $hash = '';
 3254+ if( !wfRunHooks( 'UserCryptPassword', array( &$password, &$salt, &$wgPasswordSalt, &$hash ) ) ) {
 3255+ return $hash;
 3256+ }
 3257+
32533258 if( $wgPasswordSalt ) {
32543259 if ( $salt === false ) {
32553260 $salt = substr( wfGenerateToken(), 0, 8 );
@@ -3271,6 +3276,12 @@
32723277 static function comparePasswords( $hash, $password, $userId = false ) {
32733278 $m = false;
32743279 $type = substr( $hash, 0, 3 );
 3280+
 3281+ $result = false;
 3282+ if( !wfRunHooks( 'UserComparePasswords', array( &$hash, &$password, &$userId, &$result ) ) ) {
 3283+ return $result;
 3284+ }
 3285+
32753286 if ( $type == ':A:' ) {
32763287 # Unsalted
32773288 return md5( $password ) === substr( $hash, 3 );
Index: trunk/phase3/RELEASE-NOTES
@@ -236,6 +236,8 @@
237237 * (bug 16459) Use native getElementsByClassName where possible, for better
238238 performance in modern browsers
239239 * Enable \cancel and \cancelto in texvc (recompile required)
 240+* Added 'UserCryptPassword' and 'UserComparePasswords' hooks to allow extensions to implement
 241+ their own password hashing methods.
240242
241243 === Bug fixes in 1.14 ===
242244

Status & tagging log