ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
UserPass.php
Go to the documentation of this file.
1 <?php
2 
13 
14 
19  private $users;
20 
21 
28  public function __construct($info, $config) {
29  assert(is_array($info));
30  assert(is_array($config));
31 
32  // Call the parent constructor first, as required by the interface
33  parent::__construct($info, $config);
34 
35  $this->users = array();
36 
37  // Validate and parse our configuration
38  foreach ($config as $userpass => $attributes) {
39  if (!is_string($userpass)) {
40  throw new Exception('Invalid <username>:<password> for authentication source ' .
41  $this->authId . ': ' . $userpass);
42  }
43 
44  $userpass = explode(':', $userpass, 2);
45  if (count($userpass) !== 2) {
46  throw new Exception('Invalid <username>:<password> for authentication source ' .
47  $this->authId . ': ' . $userpass[0]);
48  }
49  $username = $userpass[0];
50  $password = $userpass[1];
51 
52  try {
54  } catch(Exception $e) {
55  throw new Exception('Invalid attributes for user ' . $username .
56  ' in authentication source ' . $this->authId . ': ' .
57  $e->getMessage());
58  }
59 
60  $this->users[$username . ':' . $password] = $attributes;
61  }
62  }
63 
64 
78  protected function login($username, $password) {
79  assert(is_string($username));
80  assert(is_string($password));
81 
82  $userpass = $username . ':' . $password;
83  if (!array_key_exists($userpass, $this->users)) {
84  throw new SimpleSAML_Error_Error('WRONGUSERPASS');
85  }
86 
87  return $this->users[$userpass];
88  }
89 
90 }
static normalizeAttributesArray($attributes)
Validate and normalize an array with attributes.
Definition: Attributes.php:79
$users
Our users, stored in an associative array.
Definition: UserPass.php:19
$config
Definition: bootstrap.php:15
__construct($info, $config)
Constructor for this authentication source.
Definition: UserPass.php:28
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$password
Definition: cron.php:14
login($username, $password)
Attempt to log in using the given username and password.
Definition: UserPass.php:78
$info
Definition: index.php:5