MediaWiki master
fixWrongPasswordPrefixes.php
Go to the documentation of this file.
1<?php
10
11// @codeCoverageIgnoreStart
12require_once __DIR__ . '/Maintenance.php';
13// @codeCoverageIgnoreEnd
14
22class FixWrongPasswordPrefixes extends LoggedUpdateMaintenance {
23 public function __construct() {
24 parent::__construct();
25 $this->setBatchSize( 100 );
26 }
27
29 protected function getUpdateKey() {
30 return __CLASS__;
31 }
32
34 protected function doDBUpdates() {
35 $dbw = $this->getPrimaryDB();
36 $batchSize = $this->getBatchSize();
37 $minUserId = 0;
38
39 while ( true ) {
40 $res = $dbw->newSelectQueryBuilder()
41 ->select( [ 'user_id', 'user_password' ] )
42 ->from( 'user' )
43 ->where( $dbw->expr( 'user_id', '>', $minUserId ) )
44 ->andWhere(
45 $dbw->expr( 'user_password', IExpression::LIKE, new LikeValue( ':A:', $dbw->anyString() ) )
46 )
47 ->orderBy( 'user_id' )
48 ->limit( $batchSize )
49 ->caller( __METHOD__ )
50 ->fetchResultSet();
51
52 if ( $res->numRows() === 0 ) {
53 break;
54 }
55
56 foreach ( $res as $row ) {
57 $passwordHash = substr( $row->user_password, 3 );
58 if ( strpos( $passwordHash, ':' ) > 0 ) {
59 $dbw->newUpdateQueryBuilder()
60 ->update( 'user' )
61 ->set( [ 'user_password' => ':B:' . $passwordHash ] )
62 ->where( [ 'user_id' => $row->user_id ] )
63 ->caller( __METHOD__ )
64 ->execute();
65 }
66
67 $minUserId = $row->user_id;
68 }
69 }
70
71 $this->output( "Wrongly prefixed user password hashes, if present, have been fixed.\n" );
72 return true;
73 }
74}
75
76// @codeCoverageIgnoreStart
77$maintClass = FixWrongPasswordPrefixes::class;
78require_once RUN_MAINTENANCE_IF_MAIN;
79// @codeCoverageIgnoreEnd
An error in a previous version of MediaWiki caused B type passwords to be written with an :A: prefix ...
Content of like value.
Definition LikeValue.php:14