Repository navigation
Expand file tree
/
Copy pathAuth_phpbb.php
More file actions
937 lines (809 loc) · 30.1 KB
/
Copy pathAuth_phpbb.php
File metadata and controls
937 lines (809 loc) · 30.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* This file makes MediaWiki use a phpbb user database to
* authenticate with. This forces users to have a PHPBB account
* in order to log into the wiki. This can also force the user to
* be in a group called Wiki.
*
* With 3.0.x release this code was rewritten to make better use of
* objects and php5. Requires MediaWiki 1.11.x, PHPBB3 and PHP5.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @package MediaWiki
* @subpackage Auth_phpBB
* @author Nicholas Dunnaway
* @copyright 2004-2008 php|uber.leet
* @license http://www.gnu.org/copyleft/gpl.html
* @CVS: $Id: Auth_phpBB.php,v 3.0.3 2008/03/03 13:02:05 nkd Exp $
* @link http://uber.leetphp.com
* @version $Revision: 3.0.3 $
*
*/
error_reporting(E_ALL); // Debug
// First check if class and interface has already been defined.
if (!class_exists('AuthPlugin') || !interface_exists('iAuthPlugin'))
{
/**
* Auth Plug-in
*
*/
require_once './includes/AuthPlugin.php';
/**
* Auth Plug-in Interface
*
*/
require_once './extensions/iAuthPlugin.php';
}
// First check if the PasswordHash class has already been defined.
if (!class_exists('PasswordHash'))
{
/**
* PasswordHash Class
*
* Portable PHP password hashing framework.
*
* Written by Solar Designer <solar at openwall.com> in 2004-2006
* and placed in the public domain.
*
* The homepage URL for this framework is:
* http://www.openwall.com/phpass/
*
*/
require_once './extensions/PasswordHash.php';
}
/**
* Handles the Authentication with the PHPBB database.
*
*/
class Auth_phpBB extends AuthPlugin implements iAuthPlugin
{
/**
* Database Collation (Only change this if your know what to change it to)
*
* @var string
*/
private $_DB_Collation;
/**
* This turns on and off printing of debug information to the screen.
*
* @var bool
*/
private $_debug = false;
/**
* Name of your PHPBB groups table. (i.e. phpbb_groups)
*
* @var string
*/
private $_GroupsTB;
/**
* Message user sees when logging in.
*
* @var string
*/
private $_LoginMessage;
/**
* phpBB MySQL Database Name.
*
* @var string
*/
private $_MySQL_Database;
/**
* phpBB MySQL Host Name.
*
* @var string
*/
private $_MySQL_Host;
/**
* phpBB MySQL Password.
*
* @var string
*/
private $_MySQL_Password;
/**
* phpBB MySQL Username.
*
* @var string
*/
private $_MySQL_Username;
/**
* Version of MySQL Database.
*
* @var string
*/
private $_MySQL_Version;
/**
* Text user sees when they login and are not a member of the wiki group.
*
* @var string
*/
private $_NoWikiError;
/**
* Path to the phpBB install.
*
* @var string
*/
private $_PathToPHPBB;
/**
* Name of the phpBB session table for single session sign-on.
*
* @var string
*/
private $_SessionTB;
/**
* This tells the plugin that the phpBB tables
* are in a different database then the wiki.
* The default settings is false.
*
* @var bool
*/
private $_UseExtDatabase;
/**
* Name of your PHPBB groups table. (i.e. phpbb_groups)
*
* @var string
*/
private $_User_GroupTB;
/**
* UserID of our current user.
*
* @var int
*/
private $_UserID;
/**
* Name of your PHPBB user table. (i.e. phpbb_users)
*
* @var string
*/
private $_UserTB;
/**
* This tells the Plugin to require
* a user to be a member of the above
* phpBB group. (ie. wiki) Setting
* this to false will let any phpBB
* user edit the wiki.
*
* @var bool
*/
private $_UseWikiGroup;
/**
* Name of your PHPBB group
* users need to be a member
* of to use the wiki. (i.e. wiki)
*
* @var mixed
*/
private $_WikiGroupName;
/**
* Constructor
*
* @param array $aConfig
*/
function __construct($aConfig)
{
// Set some values phpBB needs.
define('IN_PHPBB', true); // We are secure.
// Read config
$this->_GroupsTB = $aConfig['GroupsTB'];
$this->_NoWikiError = $aConfig['NoWikiError'];
$this->_PathToPHPBB = $aConfig['PathToPHPBB'];
$this->_SessionTB = @$aConfig['SessionTB'];
$this->_UseExtDatabase = $aConfig['UseExtDatabase'];
$this->_User_GroupTB = $aConfig['User_GroupTB'];
$this->_UserTB = $aConfig['UserTB'];
$this->_UseWikiGroup = $aConfig['UseWikiGroup'];
$this->_WikiGroupName = $aConfig['WikiGroupName'];
$this->_LoginMessage = $aConfig['LoginMessage'];
// Only assign the database values if a external database is used.
if ($this->_UseExtDatabase == true)
{
$this->_MySQL_Database = $aConfig['MySQL_Database'];
$this->_MySQL_Host = $aConfig['MySQL_Host'];
$this->_MySQL_Password = $aConfig['MySQL_Password'];
$this->_MySQL_Username = $aConfig['MySQL_Username'];
}
// Set some MediaWiki Values
// This requires a user be logged into the wiki to make changes.
$GLOBALS['wgGroupPermissions']['*']['edit'] = false;
// Specify who may create new accounts:
$GLOBALS['wgGroupPermissions']['*']['createaccount'] = false;
// Load Hooks
$GLOBALS['wgHooks']['UserLoginForm'][] = array($this, 'onUserLoginForm', false);
$GLOBALS['wgHooks']['UserLoginComplete'][] = $this;
$GLOBALS['wgHooks']['UserLogout'][] = $this;
}
/**
* Allows the printing of the object.
*
*/
public function __toString()
{
echo '<pre>';
print_r($this);
echo '</pre>';
}
/**
* Add a user to the external authentication database.
* Return true if successful.
*
* NOTE: We are not allowed to add users to phpBB from the
* wiki so this always returns false.
*
* @param User $user - only the name should be assumed valid at this point
* @param string $password
* @param string $email
* @param string $realname
* @return bool
* @access public
*/
public function addUser( $user, $password, $email='', $realname='' )
{
return false;
}
/**
* Can users change their passwords?
*
* @return bool
*/
public function allowPasswordChange()
{
return true;
}
/**
* Check if a username+password pair is a valid login.
* The name will be normalized to MediaWiki's requirements, so
* you might need to munge it (for instance, for lowercase initial
* letters).
*
* @param string $username
* @param string $password
* @return bool
* @access public
* @todo Check if the password is being changed when it contains a slash or an escape char.
*/
public function authenticate($username, $password)
{
// Connect to the database.
$fresMySQLConnection = $this->connect();
$username = $this->utf8($username); // Convert to UTF8
// Check Database for username and password.
$fstrMySQLQuery = sprintf("SELECT `user_id`, `username_clean`, `user_password`
FROM `%s`
WHERE `username_clean` = '%s'
LIMIT 1",
$this->_UserTB,
mysql_real_escape_string($username, $fresMySQLConnection));
// Query Database.
$fresMySQLResult = mysql_query($fstrMySQLQuery, $fresMySQLConnection)
or die($this->mySQLError('Unable to view external table'));
while($faryMySQLResult = mysql_fetch_assoc($fresMySQLResult))
{
// Use new phpass class
$PasswordHasher = new PasswordHash(8, TRUE);
// Print the hash of the password entered by the user and the
// password hash from the database to the screen.
// While this will display its not effective anymore.
if ($this->_debug)
{
//print md5($password) . ':' . $faryMySQLResult['user_password'] . '<br />'; // Debug
print $PasswordHasher->HashPassword($password) . ':' . $faryMySQLResult['user_password'] . '<br />'; // Debug
}
/**
* Check if password submited matches the PHPBB password.
* Also check if user is a member of the phpbb group 'wiki'.
*/
if ($PasswordHasher->CheckPassword($password, $faryMySQLResult['user_password']) && $this->isMemberOfWikiGroup($username))
{
$this->_UserID = $faryMySQLResult['user_id'];
return true;
}
}
return false;
}
/**
* Return true if the wiki should create a new local account automatically
* when asked to login a user who doesn't exist locally but does in the
* external auth database.
*
* If you don't automatically create accounts, you must still create
* accounts in some way. It's not possible to authenticate without
* a local account.
*
* This is just a question, and shouldn't perform any actions.
*
* NOTE: I have set this to true to allow the wiki to create accounts.
* Without an accout in the wiki database a user will never be
* able to login and use the wiki. I think the password does not
* matter as long as authenticate() returns true.
*
* @return bool
* @access public
*/
public function autoCreate()
{
return true;
}
/**
* Check to see if external accounts can be created.
* Return true if external accounts can be created.
*
* NOTE: We are not allowed to add users to phpBB from the
* wiki so this always returns false.
*
* @return bool
* @access public
*/
public function canCreateAccounts()
{
return false;
}
/**
* Connect to the database. All of these settings are from the
* LocalSettings.php file. This assumes that the PHPBB uses the same
* database/server as the wiki.
*
* {@source }
* @return resource
*/
private function connect()
{
// Check if the phpBB tables are in a different database then the Wiki.
if ($this->_UseExtDatabase == true)
{
// Connect to database. I supress the error here.
$fresMySQLConnection = @mysql_connect($this->_MySQL_Host,
$this->_MySQL_Username,
$this->_MySQL_Password, true);
// Check if we are connected to the database.
if (!$fresMySQLConnection)
{
$this->mySQLError('There was a problem when connecting to the phpBB database.<br />' .
'Check your Host, Username, and Password settings.<br />');
}
// Select Database
$db_selected = mysql_select_db($this->_MySQL_Database, $fresMySQLConnection);
// Check if we were able to select the database.
if (!$db_selected)
{
$this->mySQLError('There was a problem when connecting to the phpBB database.<br />' .
'The database ' . $this->_MySQL_Database . ' was not found.<br />');
}
}
else
{
// Connect to database.
$fresMySQLConnection = mysql_connect($GLOBALS['wgDBserver'], $GLOBALS['wgDBuser'], $GLOBALS['wgDBpassword'], true);
// Check if we are connected to the database.
if (!$fresMySQLConnection)
{
$this->mySQLError('There was a problem when connecting to the phpBB database.<br />' .
'Check your Host, Username, and Password settings.<br />');
}
// Select Database: This assumes the wiki and phpbb are in the same database.
$db_selected = mysql_select_db($GLOBALS['wgDBname']);
// Check if we were able to select the database.
if (!$db_selected)
{
$this->mySQLError('There was a problem when connecting to the phpBB database.<br />' .
'The database ' . $GLOBALS['wgDBname'] . ' was not found.<br />');
}
}
$this->_MySQL_Version = substr(mysql_get_server_info(), 0, 3); // Get the mysql version.
mysql_query("SET NAMES 'utf8'", $fresMySQLConnection); // This is so utf8 usernames work. Needed for MySQL 4.1
return $fresMySQLConnection;
}
/**
* This turns on debugging
*
*/
public function EnableDebug()
{
$this->_debug = true;
return;
}
/**
* If you want to munge the case of an account name before the final
* check, now is your chance.
*
* @return string
*/
public function getCanonicalName( $username )
{
// Connect to the database.
$fresMySQLConnection = $this->connect();
$username = $this->utf8($username); // Convert to UTF8
// Check Database for username. We will return the correct casing of the name.
$fstrMySQLQuery = sprintf("SELECT `username_clean`
FROM `%s`
WHERE `username_clean` = '%s'
LIMIT 1",
$this->_UserTB,
mysql_real_escape_string($username, $fresMySQLConnection));
// Query Database.
$fresMySQLResult = mysql_query($fstrMySQLQuery, $fresMySQLConnection)
or die($this->mySQLError('Unable to view external table'));
while($faryMySQLResult = mysql_fetch_assoc($fresMySQLResult))
{
return ucfirst($faryMySQLResult['username_clean']);
}
// At this point the username is invalid and should return just as it was passed.
return $username;
}
/**
* When creating a user account, optionally fill in preferences and such.
* For instance, you might pull the email address or real name from the
* external user database.
*
* The User object is passed by reference so it can be modified; don't
* forget the & on your function declaration.
*
* NOTE: This gets the email address from PHPBB for the wiki account.
*
* @param User $user
* @param $autocreate bool True if user is being autocreated on login
* @access public
*/
public function initUser( &$user, $autocreate=false )
{
// Connect to the database.
$fresMySQLConnection = $this->connect();
$username = $this->utf8($user->mName); // Convert to UTF8
// Check Database for username and email address.
$fstrMySQLQuery = sprintf("SELECT `username_clean`, `user_email`
FROM `%s`
WHERE `username_clean` = '%s'
LIMIT 1",
$this->_UserTB,
mysql_real_escape_string($username, $fresMySQLConnection));
// Query Database.
$fresMySQLResult = mysql_query($fstrMySQLQuery, $fresMySQLConnection)
or die($this->mySQLError('Unable to view external table'));
while($faryMySQLResult = mysql_fetch_array($fresMySQLResult))
{
$user->mEmail = $faryMySQLResult['user_email']; // Set Email Address.
$user->mRealName = 'I need to Update My Profile'; // Set Real Name.
}
}
/**
* Checks if the user is a member of the PHPBB group called wiki.
*
* @param string $username
* @access public
* @return bool
* @todo Remove 2nd connection to database. For function isMemberOfWikiGroup()
*
*/
private function isMemberOfWikiGroup($username)
{
// In LocalSettings.php you can control if being a member of a wiki
// is required or not.
if (isset($this->_UseWikiGroup) && $this->_UseWikiGroup === false)
{
return true;
}
// Connect to the database.
$fresMySQLConnection = $this->connect();
$username = $this->utf8($username); // Convert to UTF8
$username = mysql_real_escape_string($username, $fresMySQLConnection); // Clean username.
// If not an array make this an array.
if (!is_array($this->_WikiGroupName))
{
$this->_WikiGroupName = array($this->_WikiGroupName);
}
foreach ($this->_WikiGroupName as $WikiGrpName)
{
/**
* This is a great query. It takes the username and gets the userid. Then
* it gets the group_id number of the the Wiki group. Last it checks if the
* userid and groupid are matched up. (The user is in the wiki group.)
*
* Last it returns TRUE or FALSE on if the user is in the wiki group.
*/
// Get UserId
mysql_query('SELECT @userId := `user_id` FROM `' . $this->_UserTB .
'` WHERE `username_clean` = \'' . $username . '\';', $fresMySQLConnection)
or die($this->mySQLError('Unable to get userID.'));
// Get WikiId
mysql_query('SELECT @wikiId := `group_id` FROM `' . $this->_GroupsTB .
'` WHERE `group_name` = \'' . $WikiGrpName . '\';', $fresMySQLConnection)
or die($this->mySQLError('Unable to get wikiID.'));
// Check UserId and WikiId
mysql_query('SELECT @isThere := COUNT( * ) FROM `' . $this->_User_GroupTB .
'` WHERE `user_id` = @userId AND `group_id` = @wikiId and `user_pending` = 0;', $fresMySQLConnection)
or die($this->mySQLError('Unable to get validate user group.'));
// Return Result.
$fstrMySQLQuery = 'SELECT IF(@isThere > 0, \'true\', \'false\') AS `result`;';
// Query Database.
$fresMySQLResult = mysql_query($fstrMySQLQuery, $fresMySQLConnection)
or die($this->mySQLError('Unable to view external table'));
// Check for a true or false response.
while($faryMySQLResult = mysql_fetch_array($fresMySQLResult))
{
if ($faryMySQLResult['result'] == 'true')
{
return true; // User is in Wiki group.
}
}
}
// Hook error message.
$GLOBALS['wgHooks']['UserLoginForm'][] = array($this, 'onUserLoginForm', $this->_NoWikiError);
return false; // User is not in Wiki group.
}
/**
* This loads the phpBB files that are needed.
*
*/
private function loadPHPFiles($FileSet)
{
$GLOBALS['phpbb_root_path'] = $this->_PathToPHPBB; // Path to phpBB
$GLOBALS['phpEx'] = substr(strrchr(__FILE__, '.'), 1); // File Ext.
//$phpbb_root_path = $this->_PathToPHPBB; // Path to phpBB
//$phpEx = substr(strrchr(__FILE__, '.'), 1); // File Ext.
// Check that path is valid.
if (!is_dir($this->_PathToPHPBB))
{
throw new Exception('Unable to find phpBB installed at (' . $this->_PathToPHPBB . ').');
}
switch ($FileSet)
{
case 'UTF8':
// Check for UTF file.
if (!is_file($this->_PathToPHPBB . 'includes/utf/utf_tools.php'))
{
throw new Exception('Unable to find phpbb\'s utf_tools.php file at (' . $this->_PathToPHPBB . '/includes/utf/utf_tools.php). Please check that phpBB is installed.');
}
// Load the phpBB file.
require_once $this->_PathToPHPBB . 'includes/utf/utf_tools.php';
break;
case 'phpBBLogin':
break;
case 'phpBBLogout':
break;
}
}
/**
* Modify options in the login template.
*
* NOTE: Turned off some Template stuff here. Anyone who knows where
* to find all the template options please let me know. I was only able
* to find a few.
*
* @param UserLoginTemplate $template
* @access public
*/
public function modifyUITemplate( &$template )
{
$template->set('usedomain', false); // We do not want a domain name.
$template->set('create', false); // Remove option to create new accounts from the wiki.
$template->set('useemail', false); // Disable the mail new password box.
}
/**
* This prints an error when a MySQL error is found.
*
* @param string $message
* @access public
*/
private function mySQLError( $message )
{
throw new Exception($message . '<br />' . 'MySQL Error Number: ' . mysql_errno() . '<br />' . 'MySQL Error Message: ' . mysql_error() . '<br /><br />');
}
/**
* This is the hook that runs when a user logs in. This is where the
* code to auto log-in a user to phpBB should go.
*
* Note: Right now it does nothing,
*
* @param object $user
* @return bool
*/
public function onUserLoginComplete(&$user)
{
// @ToDo: Add code here to auto log into the forum.
return true;
}
/**
* Here we add some text to the login screen telling the user
* they need a phpBB account to login to the wiki.
*
* Note: This is a hook.
*
* @param string $errorMessage
* @param object $template
* @return bool
*/
public function onUserLoginForm($errorMessage = false, $template)
{
$template->data['link'] = $this->_LoginMessage;
// If there is an error message display it.
if ($errorMessage)
{
$template->data['message'] = $errorMessage;
$template->data['messagetype'] = 'error';
}
return true;
}
/**
* This is the Hook that gets called when a user logs out.
*
* @param object $user
*/
public function onUserLogout(&$user)
{
// User logs out of the wiki we want to log them out of the form too.
if (!isset($this->_SessionTB))
{
return true; // If the value is not set just return true and move on.
}
return true;
// @todo: Add code here to delete the session.
}
/**
* Set the domain this plugin is supposed to use when authenticating.
*
* NOTE: We do not use this.
*
* @param string $domain
* @access public
*/
public function setDomain( $domain )
{
$this->domain = $domain;
}
/**
* Set the given password in the authentication database.
* As a special case, the password may be set to null to request
* locking the password to an unusable value, with the expectation
* that it will be set later through a mail reset or other method.
*
* Return true if successful.
*
* NOTE: We only allow the user to change their password via phpBB.
*
* @param $user User object.
* @param $password String: password.
* @return bool
* @access public
*/
public function setPassword( $user, $password )
{
return true;
}
/**
* Return true to prevent logins that don't authenticate here from being
* checked against the local database's password fields.
*
* This is just a question, and shouldn't perform any actions.
*
* Note: This forces a user to pass Authentication with the above
* function authenticate(). So if a user changes their PHPBB
* password, their old one will not work to log into the wiki.
* Wiki does not have a way to update it's password when PHPBB
* does. This however does not matter.
*
* @return bool
* @access public
*/
public function strict()
{
return true;
}
/**
* Update user information in the external authentication database.
* Return true if successful.
*
* @param $user User object.
* @return bool
* @access public
*/
public function updateExternalDB( $user )
{
return true;
}
/**
* When a user logs in, optionally fill in preferences and such.
* For instance, you might pull the email address or real name from the
* external user database.
*
* The User object is passed by reference so it can be modified; don't
* forget the & on your function declaration.
*
* NOTE: Not useing right now.
*
* @param User $user
* @access public
* @return bool
*/
public function updateUser( &$user )
{
return true;
}
/**
* Check whether there exists a user account with the given name.
* The name will be normalized to MediaWiki's requirements, so
* you might need to munge it (for instance, for lowercase initial
* letters).
*
* NOTE: MediaWiki checks its database for the username. If it has
* no record of the username it then asks. "Is this really a
* valid username?" If not then MediaWiki fails Authentication.
*
* @param string $username
* @return bool
* @access public
*/
public function userExists($username)
{
// Connect to the database.
$fresMySQLConnection = $this->connect();
// If debug is on print the username entered by the user and the one from the datebase to the screen.
if ($this->_debug)
{
print $username . ' : ' . $this->utf8($username); // Debug
}
$username = $this->utf8($username); // Convert to UTF8
// Check Database for username.
$fstrMySQLQuery = sprintf("SELECT `username_clean`
FROM `%s`
WHERE `username_clean` = '%s'
LIMIT 1",
$this->_UserTB,
mysql_real_escape_string($username, $fresMySQLConnection));
// Query Database.
$fresMySQLResult = mysql_query($fstrMySQLQuery, $fresMySQLConnection)
or die($this->mySQLError('Unable to view external table'));
while($faryMySQLResult = mysql_fetch_array($fresMySQLResult))
{
// If debug is on print the username entered by the user and the one from the datebase to the screen.
if ($this->_debug)
{
print $username . ' : ' . $faryMySQLResult['username_clean']; // Debug
}
// Double check match.
if ($username == $faryMySQLResult['username_clean'])
{
return true; // Pass
}
}
return false; // Fail
}
/**
* Cleans a username using PHPBB functions
*
* @param string $username
* @return string
*/
private function utf8($username)
{
$this->loadPHPFiles('UTF8'); // Load files needed to clean username.
error_reporting(E_ALL ^ E_NOTICE); // remove notices because phpBB does not use include once.
$username = utf8_clean_string($username);
error_reporting(E_ALL);
return $username;
}
/**
* Check to see if the specific domain is a valid domain.
*
* @param string $domain
* @return bool
* @access public
*/
public function validDomain( $domain )
{
return true;
}
}
?>