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
|
<?php
declare(strict_types=1);
namespace SimpleSAML\Module\core\Auth\Source;
use SimpleSAML\Configuration;
use SimpleSAML\Error;
/**
* Authentication source which verifies the password against
* the 'auth.adminpassword' configuration option.
*
* @package SimpleSAMLphp
*/
class AdminPassword extends \SimpleSAML\Module\core\Auth\UserPassBase
{
/**
* Constructor for this authentication source.
*
* @param array $info Information about this authentication source.
* @param array $config Configuration.
*/
public function __construct($info, $config)
{
assert(is_array($info));
assert(is_array($config));
// Call the parent constructor first, as required by the interface
parent::__construct($info, $config);
$this->setForcedUsername("admin");
}
/**
* Attempt to log in using the given username and password.
*
* On a successful login, this function should return the users attributes. On failure,
* it should throw an exception. If the error was caused by the user entering the wrong
* username or password, a \SimpleSAML\Error\Error('WRONGUSERPASS') should be thrown.
*
* Note that both the username and the password are UTF-8 encoded.
*
* @param string $username The username the user wrote.
* @param string $password The password the user wrote.
* @return array Associative array with the users attributes.
*/
protected function login($username, $password)
{
assert(is_string($username));
assert(is_string($password));
$config = Configuration::getInstance();
$adminPassword = $config->getString('auth.adminpassword', '123');
if ($adminPassword === '123') {
// We require that the user changes the password
throw new Error\Error('NOTSET');
}
if ($username !== "admin") {
throw new Error\Error('WRONGUSERPASS');
}
if (!\SimpleSAML\Utils\Crypto::pwValid($adminPassword, $password)) {
throw new Error\Error('WRONGUSERPASS');
}
return ['user' => ['admin']];
}
}
|