1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- /**
- * File Auth driver.
- * [!!] this Auth driver does not support roles nor autologin.
- *
- * @package KO7/Auth
- *
- * @copyright (c) 2007-2016 Kohana Team
- * @copyright (c) since 2016 Koseven Team
- * @license https://koseven.dev/LICENSE
- */
- class KO7_Auth_File extends Auth {
- // User list
- protected $_users;
- /**
- * Constructor loads the user list into the class.
- */
- public function __construct($config = [])
- {
- parent::__construct($config);
- // Load user list
- $this->_users = Arr::get($config, 'users', []);
- }
- /**
- * Logs a user in.
- *
- * @param string $username Username
- * @param string $password Password
- * @param boolean $remember Enable autologin (not supported)
- * @return boolean
- */
- protected function _login($username, $password, $remember)
- {
- if ($remember)
- {
- throw new KO7_Exception('File based auth does not support remember');
- }
- if (is_string($password))
- {
- // Create a hashed password
- $password = $this->hash($password);
- }
- if (isset($this->_users[$username]) AND $this->_users[$username] === $password)
- {
- // Complete the login
- return $this->complete_login($username);
- }
- // Login failed
- return FALSE;
- }
- /**
- * Forces a user to be logged in, without specifying a password.
- *
- * @param mixed $username Username
- * @return boolean
- */
- public function force_login($username)
- {
- // Complete the login
- return $this->complete_login($username);
- }
- /**
- * Get the stored password for a username.
- *
- * @param mixed $username Username
- * @return string
- */
- public function password($username)
- {
- return Arr::get($this->_users, $username, FALSE);
- }
- /**
- * Compare password with original (plain text). Works for current (logged in) user
- *
- * @param string $password Password
- * @return boolean
- */
- public function check_password($password)
- {
- $username = $this->get_user();
- if ($username === FALSE)
- return FALSE;
- return ($password === $this->password($username));
- }
- }
|