Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / extauth / Hardcoded.php
1 <?php
2 /**
3 * External authentication with hardcoded user names and passwords
4 *
5 * Copyright © 2009 Aryeh Gregor
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 */
24
25 /**
26 * This class supports external authentication from a literal array dumped in
27 * LocalSettings.php. It's mostly useful for testing. Example configuration:
28 *
29 * $wgExternalAuthType = 'ExternalUser_Hardcoded';
30 * $wgExternalAuthConf = array(
31 * 'Bob Smith' => array(
32 * 'password' => 'literal string',
33 * 'emailaddress' => 'bob@example.com',
34 * ),
35 * );
36 *
37 * Multiple names may be provided. The keys of the inner arrays can be either
38 * 'password', or the name of any preference.
39 *
40 * @ingroup ExternalUser
41 */
42 class ExternalUser_Hardcoded extends ExternalUser {
43 private $mName;
44
45 protected function initFromName( $name ) {
46 global $wgExternalAuthConf;
47
48 if ( isset( $wgExternalAuthConf[$name] ) ) {
49 $this->mName = $name;
50 return true;
51 }
52 return false;
53 }
54
55 protected function initFromId( $id ) {
56 return $this->initFromName( $id );
57 }
58
59 public function getId() {
60 return $this->mName;
61 }
62
63 public function getName() {
64 return $this->mName;
65 }
66
67 public function authenticate( $password ) {
68 global $wgExternalAuthConf;
69
70 return isset( $wgExternalAuthConf[$this->mName]['password'] )
71 && $wgExternalAuthConf[$this->mName]['password'] == $password;
72 }
73
74 public function getPref( $pref ) {
75 global $wgExternalAuthConf;
76
77 if ( isset( $wgExternalAuthConf[$this->mName][$pref] ) ) {
78 return $wgExternalAuthConf[$this->mName][$pref];
79 }
80 return null;
81 }
82
83 # TODO: Implement setPref() via regex on LocalSettings. (Just kidding.)
84 }