Patch by Ivan Krstic, slightly modified, for the session handler wrong setting problem.
[lhc/web/wiklou.git] / includes / User.php
1 <?php
2 # See user.doc
3
4 require_once( 'WatchedItem.php' );
5
6 class User {
7 /* private */ var $mId, $mName, $mPassword, $mEmail, $mNewtalk;
8 /* private */ var $mRights, $mOptions;
9 /* private */ var $mDataLoaded, $mNewpassword;
10 /* private */ var $mSkin;
11 /* private */ var $mBlockedby, $mBlockreason;
12 /* private */ var $mTouched;
13 /* private */ var $mCookiePassword;
14 /* private */ var $mRealName;
15 /* private */ var $mHash;
16
17 function User() {
18 $this->loadDefaults();
19 }
20
21 # Static factory method
22 #
23 function newFromName( $name ) {
24 $u = new User();
25
26 # Clean up name according to title rules
27
28 $t = Title::newFromText( $name );
29 $u->setName( $t->getText() );
30 return $u;
31 }
32
33 /* static */ function whoIs( $id ) {
34 $dbr =& wfGetDB( DB_SLAVE );
35 return $dbr->getField( 'user', 'user_name', array( 'user_id' => $id ) );
36 }
37
38 /* static */ function whoIsReal( $id ) {
39 $dbr =& wfGetDB( DB_SLAVE );
40 return $dbr->getField( 'user', 'user_real_name', array( 'user_id' => $id ) );
41 }
42
43 /* static */ function idFromName( $name ) {
44 $fname = "User::idFromName";
45
46 $nt = Title::newFromText( $name );
47 if( is_null( $nt ) ) {
48 # Illegal name
49 return null;
50 }
51 $dbr =& wfGetDB( DB_SLAVE );
52 $s = $dbr->getArray( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), $fname );
53
54 if ( $s === false ) {
55 return 0;
56 } else {
57 return $s->user_id;
58 }
59 }
60
61 # does the string match an anonymous user IP address?
62 /* static */ function isIP( $name ) {
63 return preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$name);
64
65 }
66
67 /* static */ function randomPassword() {
68 $pwchars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz';
69 $l = strlen( $pwchars ) - 1;
70
71 $np = $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} .
72 $pwchars{mt_rand( 0, $l )} . chr( mt_rand(48, 57) ) .
73 $pwchars{mt_rand( 0, $l )} . $pwchars{mt_rand( 0, $l )} .
74 $pwchars{mt_rand( 0, $l )};
75 return $np;
76 }
77
78 function loadDefaults() {
79 global $wgLang, $wgIP;
80 global $wgNamespacesToBeSearchedDefault;
81
82 $this->mId = $this->mNewtalk = 0;
83 $this->mName = $wgIP;
84 $this->mRealName = $this->mEmail = '';
85 $this->mPassword = $this->mNewpassword = '';
86 $this->mRights = array();
87 $defOpt = $wgLang->getDefaultUserOptions() ;
88 foreach ( $defOpt as $oname => $val ) {
89 $this->mOptions[$oname] = $val;
90 }
91 foreach ($wgNamespacesToBeSearchedDefault as $nsnum => $val) {
92 $this->mOptions['searchNs'.$nsnum] = $val;
93 }
94 unset( $this->mSkin );
95 $this->mDataLoaded = false;
96 $this->mBlockedby = -1; # Unset
97 $this->mTouched = '0'; # Allow any pages to be cached
98 $this->cookiePassword = '';
99 $this->mHash = false;
100 }
101
102 /* private */ function getBlockedStatus()
103 {
104 global $wgIP, $wgBlockCache, $wgProxyList;
105
106 if ( -1 != $this->mBlockedby ) { return; }
107
108 $this->mBlockedby = 0;
109
110 # User blocking
111 if ( $this->mId ) {
112 $block = new Block();
113 if ( $block->load( $wgIP , $this->mId ) ) {
114 $this->mBlockedby = $block->mBy;
115 $this->mBlockreason = $block->mReason;
116 }
117 }
118
119 # IP/range blocking
120 if ( !$this->mBlockedby ) {
121 $block = $wgBlockCache->get( $wgIP );
122 if ( $block !== false ) {
123 $this->mBlockedby = $block->mBy;
124 $this->mBlockreason = $block->mReason;
125 }
126 }
127
128 # Proxy blocking
129 if ( !$this->mBlockedby ) {
130 if ( array_key_exists( $wgIP, $wgProxyList ) ) {
131 $this->mBlockreason = wfMsg( 'proxyblockreason' );
132 $this->mBlockedby = "Proxy blocker";
133 }
134 }
135 }
136
137 function isBlocked()
138 {
139 $this->getBlockedStatus();
140 if ( 0 === $this->mBlockedby ) { return false; }
141 return true;
142 }
143
144 function blockedBy() {
145 $this->getBlockedStatus();
146 return $this->mBlockedby;
147 }
148
149 function blockedFor() {
150 $this->getBlockedStatus();
151 return $this->mBlockreason;
152 }
153
154 function SetupSession() {
155 global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
156 if( $wgSessionsInMemcached ) {
157 require_once( 'MemcachedSessions.php' );
158 } elseif( 'files' != ini_get( 'session.save_handler' ) ) {
159 # If it's left on 'user' or another setting from another
160 # application, it will end up failing. Try to recover.
161 ini_set ( 'session.save_handler', 'files' );
162 }
163 session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
164 session_cache_limiter( 'private, must-revalidate' );
165 @session_start();
166 }
167
168 /* static */ function loadFromSession()
169 {
170 global $wgMemc, $wgDBname;
171
172 if ( isset( $_SESSION['wsUserID'] ) ) {
173 if ( 0 != $_SESSION['wsUserID'] ) {
174 $sId = $_SESSION['wsUserID'];
175 } else {
176 return new User();
177 }
178 } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
179 $sId = IntVal( $_COOKIE["{$wgDBname}UserID"] );
180 $_SESSION['wsUserID'] = $sId;
181 } else {
182 return new User();
183 }
184 if ( isset( $_SESSION['wsUserName'] ) ) {
185 $sName = $_SESSION['wsUserName'];
186 } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
187 $sName = $_COOKIE["{$wgDBname}UserName"];
188 $_SESSION['wsUserName'] = $sName;
189 } else {
190 return new User();
191 }
192
193 $passwordCorrect = FALSE;
194 $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
195 if($makenew = !$user) {
196 wfDebug( "User::loadFromSession() unable to load from memcached\n" );
197 $user = new User();
198 $user->mId = $sId;
199 $user->loadFromDatabase();
200 } else {
201 wfDebug( "User::loadFromSession() got from cache!\n" );
202 }
203
204 if ( isset( $_SESSION['wsUserPassword'] ) ) {
205 $passwordCorrect = $_SESSION['wsUserPassword'] == $user->mPassword;
206 } else if ( isset( $_COOKIE["{$wgDBname}Password"] ) ) {
207 $user->mCookiePassword = $_COOKIE["{$wgDBname}Password"];
208 $_SESSION['wsUserPassword'] = $user->addSalt( $user->mCookiePassword );
209 $passwordCorrect = $_SESSION['wsUserPassword'] == $user->mPassword;
210 } else {
211 return new User(); # Can't log in from session
212 }
213
214 if ( ( $sName == $user->mName ) && $passwordCorrect ) {
215 if($makenew) {
216 if($wgMemc->set( $key, $user ))
217 wfDebug( "User::loadFromSession() successfully saved user\n" );
218 else
219 wfDebug( "User::loadFromSession() unable to save to memcached\n" );
220 }
221 $user->spreadBlock();
222 return $user;
223 }
224 return new User(); # Can't log in from session
225 }
226
227 function loadFromDatabase()
228 {
229 global $wgCommandLineMode;
230 $fname = "User::loadFromDatabase";
231 if ( $this->mDataLoaded || $wgCommandLineMode ) {
232 return;
233 }
234
235 # Paranoia
236 $this->mId = IntVal( $this->mId );
237
238 # check in separate table if there are changes to the talk page
239 $this->mNewtalk=0; # reset talk page status
240 $dbr =& wfGetDB( DB_SLAVE );
241 if($this->mId) {
242 $res = $dbr->select( 'user_newtalk', 1, array( 'user_id' => $this->mId ), $fname );
243
244 if ( $dbr->numRows($res)>0 ) {
245 $this->mNewtalk= 1;
246 }
247 $dbr->freeResult( $res );
248 } else {
249 global $wgDBname, $wgMemc;
250 $key = "$wgDBname:newtalk:ip:{$this->mName}";
251 $newtalk = $wgMemc->get( $key );
252 if( ! is_integer( $newtalk ) ){
253 $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->mName ), $fname );
254
255 $this->mNewtalk = $dbr->numRows( $res ) > 0 ? 1 : 0;
256 $dbr->freeResult( $res );
257
258 $wgMemc->set( $key, $this->mNewtalk, time() ); // + 1800 );
259 } else {
260 $this->mNewtalk = $newtalk ? 1 : 0;
261 }
262 }
263 if(!$this->mId) {
264 $this->mDataLoaded = true;
265 return;
266 } # the following stuff is for non-anonymous users only
267
268 $s = $dbr->getArray( 'user', array( 'user_name','user_password','user_newpassword','user_email',
269 'user_real_name','user_options','user_rights','user_touched' ),
270 array( 'user_id' => $this->mId ), $fname );
271
272 if ( $s !== false ) {
273 $this->mName = $s->user_name;
274 $this->mEmail = $s->user_email;
275 $this->mRealName = $s->user_real_name;
276 $this->mPassword = $s->user_password;
277 $this->mNewpassword = $s->user_newpassword;
278 $this->decodeOptions( $s->user_options );
279 $this->mRights = explode( ",", strtolower( $s->user_rights ) );
280 $this->mTouched = wfTimestamp(TS_MW,$s->user_touched);
281 }
282
283 $this->mDataLoaded = true;
284 }
285
286 function getID() { return $this->mId; }
287 function setID( $v ) {
288 $this->mId = $v;
289 $this->mDataLoaded = false;
290 }
291
292 function getName() {
293 $this->loadFromDatabase();
294 return $this->mName;
295 }
296
297 function setName( $str ) {
298 $this->loadFromDatabase();
299 $this->mName = $str;
300 }
301
302 function getNewtalk() {
303 $this->loadFromDatabase();
304 return ( 0 != $this->mNewtalk );
305 }
306
307 function setNewtalk( $val )
308 {
309 $this->loadFromDatabase();
310 $this->mNewtalk = $val;
311 $this->invalidateCache();
312 }
313
314 function invalidateCache() {
315 $this->loadFromDatabase();
316 $this->mTouched = wfTimestampNow();
317 # Don't forget to save the options after this or
318 # it won't take effect!
319 }
320
321 function validateCache( $timestamp ) {
322 $this->loadFromDatabase();
323 return ($timestamp >= $this->mTouched);
324 }
325
326 function addSalt( $p ) {
327 global $wgPasswordSalt;
328 if($wgPasswordSalt)
329 return md5( "{$this->mId}-{$p}" );
330 else
331 return $p;
332 }
333
334 function encryptPassword( $p ) {
335 return $this->addSalt( md5( $p ) );
336 }
337
338 function setPassword( $str ) {
339 $this->loadFromDatabase();
340 $this->setCookiePassword( $str );
341 $this->mPassword = $this->encryptPassword( $str );
342 $this->mNewpassword = '';
343 }
344
345 function setCookiePassword( $str ) {
346 $this->loadFromDatabase();
347 $this->mCookiePassword = md5( $str );
348 }
349
350 function setNewpassword( $str ) {
351 $this->loadFromDatabase();
352 $this->mNewpassword = $this->encryptPassword( $str );
353 }
354
355 function getEmail() {
356 $this->loadFromDatabase();
357 return $this->mEmail;
358 }
359
360 function setEmail( $str ) {
361 $this->loadFromDatabase();
362 $this->mEmail = $str;
363 }
364
365 function getRealName() {
366 $this->loadFromDatabase();
367 return $this->mRealName;
368 }
369
370 function setRealName( $str ) {
371 $this->loadFromDatabase();
372 $this->mRealName = $str;
373 }
374
375 function getOption( $oname ) {
376 $this->loadFromDatabase();
377 if ( array_key_exists( $oname, $this->mOptions ) ) {
378 return $this->mOptions[$oname];
379 } else {
380 return '';
381 }
382 }
383
384 function setOption( $oname, $val ) {
385 $this->loadFromDatabase();
386 if ( $oname == 'skin' ) {
387 # Clear cached skin, so the new one displays immediately in Special:Preferences
388 unset( $this->mSkin );
389 }
390 $this->mOptions[$oname] = $val;
391 $this->invalidateCache();
392 }
393
394 function getRights() {
395 $this->loadFromDatabase();
396 return $this->mRights;
397 }
398
399 function addRight( $rname ) {
400 $this->loadFromDatabase();
401 array_push( $this->mRights, $rname );
402 $this->invalidateCache();
403 }
404
405 function isSysop() {
406 $this->loadFromDatabase();
407 if ( 0 == $this->mId ) { return false; }
408
409 return in_array( 'sysop', $this->mRights );
410 }
411
412 function isDeveloper() {
413 $this->loadFromDatabase();
414 if ( 0 == $this->mId ) { return false; }
415
416 return in_array( 'developer', $this->mRights );
417 }
418
419 function isBureaucrat() {
420 $this->loadFromDatabase();
421 if ( 0 == $this->mId ) { return false; }
422
423 return in_array( 'bureaucrat', $this->mRights );
424 }
425
426 function isBot() {
427 $this->loadFromDatabase();
428
429 # Why was this here? I need a UID=0 conversion script [TS]
430 # if ( 0 == $this->mId ) { return false; }
431
432 return in_array( 'bot', $this->mRights );
433 }
434
435 function &getSkin() {
436 if ( ! isset( $this->mSkin ) ) {
437 # get all skin names available from SkinNames.php
438 $skinNames = Skin::getSkinNames();
439 # get the user skin
440 $userSkin = $this->getOption( 'skin' );
441 if ( $userSkin == '' ) { $userSkin = 'standard'; }
442
443 if ( !isset( $skinNames[$userSkin] ) ) {
444 # in case the user skin could not be found find a replacement
445 $fallback = array(
446 0 => 'SkinStandard',
447 1 => 'SkinNostalgia',
448 2 => 'SkinCologneBlue');
449 # if phptal is enabled we should have monobook skin that superseed
450 # the good old SkinStandard.
451 if ( isset( $skinNames['monobook'] ) ) {
452 $fallback[0] = 'SkinMonoBook';
453 }
454
455 if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
456 $sn = $fallback[$userSkin];
457 } else {
458 $sn = 'SkinStandard';
459 }
460 } else {
461 # The user skin is available
462 $sn = 'Skin' . $skinNames[$userSkin];
463 }
464
465 # only require the needed stuff
466 switch($sn) {
467 case 'SkinMonoBook':
468 require_once( 'SkinPHPTal.php' );
469 break;
470 case 'SkinStandard':
471 require_once( 'SkinStandard.php' );
472 break;
473 case 'SkinNostalgia':
474 require_once( 'SkinNostalgia.php' );
475 break;
476 case 'SkinCologneBlue':
477 require_once( 'SkinCologneBlue.php' );
478 break;
479 }
480 # now we can create the skin object
481 $this->mSkin = new $sn;
482 }
483 return $this->mSkin;
484 }
485
486 function isWatched( $title ) {
487 $wl = WatchedItem::fromUserTitle( $this, $title );
488 return $wl->isWatched();
489 }
490
491 function addWatch( $title ) {
492 $wl = WatchedItem::fromUserTitle( $this, $title );
493 $wl->addWatch();
494 $this->invalidateCache();
495 }
496
497 function removeWatch( $title ) {
498 $wl = WatchedItem::fromUserTitle( $this, $title );
499 $wl->removeWatch();
500 $this->invalidateCache();
501 }
502
503
504 /* private */ function encodeOptions() {
505 $a = array();
506 foreach ( $this->mOptions as $oname => $oval ) {
507 array_push( $a, $oname.'='.$oval );
508 }
509 $s = implode( "\n", $a );
510 return $s;
511 }
512
513 /* private */ function decodeOptions( $str ) {
514 $a = explode( "\n", $str );
515 foreach ( $a as $s ) {
516 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
517 $this->mOptions[$m[1]] = $m[2];
518 }
519 }
520 }
521
522 function setCookies() {
523 global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
524 if ( 0 == $this->mId ) return;
525 $this->loadFromDatabase();
526 $exp = time() + $wgCookieExpiration;
527
528 $_SESSION['wsUserID'] = $this->mId;
529 setcookie( $wgDBname.'UserID', $this->mId, $exp, $wgCookiePath, $wgCookieDomain );
530
531 $_SESSION['wsUserName'] = $this->mName;
532 setcookie( $wgDBname.'UserName', $this->mName, $exp, $wgCookiePath, $wgCookieDomain );
533
534 $_SESSION['wsUserPassword'] = $this->mPassword;
535 if ( 1 == $this->getOption( 'rememberpassword' ) ) {
536 setcookie( $wgDBname.'Password', $this->mCookiePassword, $exp, $wgCookiePath, $wgCookieDomain );
537 } else {
538 setcookie( $wgDBname.'Password', '', time() - 3600 );
539 }
540 }
541
542 function logout() {
543 global $wgCookiePath, $wgCookieDomain, $wgDBname;
544 $this->mId = 0;
545
546 $_SESSION['wsUserID'] = 0;
547
548 setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
549 setcookie( $wgDBname.'Password', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
550 }
551
552 function saveSettings() {
553 global $wgMemc, $wgDBname;
554 $fname = 'User::saveSettings';
555
556 $dbw =& wfGetDB( DB_MASTER );
557 if ( ! $this->mNewtalk ) {
558 # Delete user_newtalk row
559 if( $this->mId ) {
560 $dbw->delete( 'user_newtalk', array( 'user_id' => $this->mId ), $fname );
561 } else {
562 $dbw->delete( 'user_newtalk', array( 'user_ip' => $this->mName ), $fname );
563 $wgMemc->delete( "$wgDBname:newtalk:ip:{$this->mName}" );
564 }
565 }
566 if ( 0 == $this->mId ) { return; }
567
568 $dbw->update( 'user',
569 array( /* SET */
570 'user_name' => $this->mName,
571 'user_password' => $this->mPassword,
572 'user_newpassword' => $this->mNewpassword,
573 'user_real_name' => $this->mRealName,
574 'user_email' => $this->mEmail,
575 'user_options' => $this->encodeOptions(),
576 'user_rights' => implode( ",", $this->mRights ),
577 'user_touched' => $dbw->timestamp($this->mTouched)
578 ), array( /* WHERE */
579 'user_id' => $this->mId
580 ), $fname
581 );
582 $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
583 }
584
585 # Checks if a user with the given name exists, returns the ID
586 #
587 function idForName() {
588 $fname = 'User::idForName';
589
590 $gotid = 0;
591 $s = trim( $this->mName );
592 if ( 0 == strcmp( '', $s ) ) return 0;
593
594 $dbr =& wfGetDB( DB_SLAVE );
595 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), $fname );
596 if ( $id === false ) {
597 $id = 0;
598 }
599 return $id;
600 }
601
602 function addToDatabase() {
603 $fname = 'User::addToDatabase';
604 $dbw =& wfGetDB( DB_MASTER );
605 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
606 $dbw->insert( 'user',
607 array(
608 'user_id' => $seqVal,
609 'user_name' => $this->mName,
610 'user_password' => $this->mPassword,
611 'user_newpassword' => $this->mNewpassword,
612 'user_email' => $this->mEmail,
613 'user_real_name' => $this->mRealName,
614 'user_rights' => implode( ',', $this->mRights ),
615 'user_options' => $this->encodeOptions()
616 ), $fname
617 );
618 $this->mId = $dbw->insertId();
619 }
620
621 function spreadBlock()
622 {
623 global $wgIP;
624 # If the (non-anonymous) user is blocked, this function will block any IP address
625 # that they successfully log on from.
626 $fname = 'User::spreadBlock';
627
628 wfDebug( "User:spreadBlock()\n" );
629 if ( $this->mId == 0 ) {
630 return;
631 }
632
633 $userblock = Block::newFromDB( '', $this->mId );
634 if ( !$userblock->isValid() ) {
635 return;
636 }
637
638 # Check if this IP address is already blocked
639 $ipblock = Block::newFromDB( $wgIP );
640 if ( $ipblock->isValid() ) {
641 # Just update the timestamp
642 $ipblock->updateTimestamp();
643 return;
644 }
645
646 # Make a new block object with the desired properties
647 wfDebug( "Autoblocking {$this->mName}@{$wgIP}\n" );
648 $ipblock->mAddress = $wgIP;
649 $ipblock->mUser = 0;
650 $ipblock->mBy = $userblock->mBy;
651 $ipblock->mReason = wfMsg( 'autoblocker', $this->getName(), $userblock->mReason );
652 $ipblock->mTimestamp = wfTimestampNow();
653 $ipblock->mAuto = 1;
654 # If the user is already blocked with an expiry date, we don't
655 # want to pile on top of that!
656 if($userblock->mExpiry) {
657 $ipblock->mExpiry = min ( $userblock->mExpiry, Block::getAutoblockExpiry( $ipblock->mTimestamp ));
658 } else {
659 $ipblock->mExpiry = Block::getAutoblockExpiry( $ipblock->mTimestamp );
660 }
661
662 # Insert it
663 $ipblock->insert();
664
665 }
666
667 function getPageRenderingHash(){
668 if( $this->mHash ){
669 return $this->mHash;
670 }
671
672 // stubthreshold is only included below for completeness,
673 // it will always be 0 when this function is called by parsercache.
674
675 $confstr = $this->getOption( 'math' );
676 $confstr .= '!' . $this->getOption( 'highlightbroken' );
677 $confstr .= '!' . $this->getOption( 'stubthreshold' );
678 $confstr .= '!' . $this->getOption( 'editsection' );
679 $confstr .= '!' . $this->getOption( 'editsectiononrightclick' );
680 $confstr .= '!' . $this->getOption( 'showtoc' );
681 $confstr .= '!' . $this->getOption( 'date' );
682 $confstr .= '!' . $this->getOption( 'numberheadings' );
683
684 $this->mHash = $confstr;
685 return $confstr ;
686 }
687
688 function isAllowedToCreateAccount() {
689 global $wgWhitelistAccount;
690 $allowed = false;
691
692 if (!$wgWhitelistAccount) { return 1; }; // default behaviour
693 foreach ($wgWhitelistAccount as $right => $ok) {
694 $userHasRight = (!strcmp($right, 'user') || in_array($right, $this->getRights()));
695 $allowed |= ($ok && $userHasRight);
696 }
697 return $allowed;
698 }
699
700 # Set mDataLoaded, return previous value
701 # Use this to prevent DB access in command-line scripts or similar situations
702 function setLoaded( $loaded )
703 {
704 return wfSetVar( $this->mDataLoaded, $loaded );
705 }
706
707 function getUserPage() {
708 return Title::makeTitle( NS_USER, $this->mName );
709 }
710
711 /* static */ function getMaxID() {
712 $dbr =& wfGetDB( DB_SLAVE );
713 return $dbr->selectField( 'user', 'max(user_id)', false );
714 }
715
716 function isNewbie() {
717 return $this->mId > User::getMaxID() * 0.99 && !$this->isSysop() && !$this->isBot() || $this->getID() == 0;
718 }
719
720 # Check to see if the given clear-text password is one of the accepted passwords
721 function checkPassword( $password ) {
722 $this->loadFromDatabase();
723 $ep = $this->encryptPassword( $password );
724 if ( 0 == strcmp( $ep, $this->mPassword ) ) {
725 return true;
726 } elseif ( 0 == strcmp( $ep, $this->mNewpassword ) ) {
727 return true;
728 } elseif ( function_exists( 'iconv' ) ) {
729 # Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
730 # Check for this with iconv
731 /* $cp1252hash = $this->encryptPassword( iconv( 'UTF-8', 'WINDOWS-1252', $password ) );
732 if ( 0 == strcmp( $cp1252hash, $this->mPassword ) ) {
733 return true;
734 }*/
735 }
736 return false;
737 }
738 }
739
740 ?>