2012-11-09 12:18:50 +00:00
|
|
|
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
2010-08-21 04:43:03 +00:00
|
|
|
/**
|
|
|
|
* File Auth driver.
|
|
|
|
* [!!] this Auth driver does not support roles nor autologin.
|
|
|
|
*
|
|
|
|
* @package Kohana/Auth
|
|
|
|
* @author Kohana Team
|
2012-11-09 12:18:50 +00:00
|
|
|
* @copyright (c) 2007-2012 Kohana Team
|
2011-05-13 06:00:25 +00:00
|
|
|
* @license http://kohanaframework.org/license
|
2010-08-21 04:43:03 +00:00
|
|
|
*/
|
|
|
|
class Kohana_Auth_File extends Auth {
|
|
|
|
|
|
|
|
// User list
|
|
|
|
protected $_users;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor loads the user list into the class.
|
|
|
|
*/
|
|
|
|
public function __construct($config = array())
|
|
|
|
{
|
|
|
|
parent::__construct($config);
|
|
|
|
|
|
|
|
// Load user list
|
|
|
|
$this->_users = Arr::get($config, 'users', array());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs a user in.
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param string $username Username
|
|
|
|
* @param string $password Password
|
|
|
|
* @param boolean $remember Enable autologin (not supported)
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
protected function _login($username, $password, $remember)
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
if (is_string($password))
|
|
|
|
{
|
|
|
|
// Create a hashed password
|
|
|
|
$password = $this->hash($password);
|
|
|
|
}
|
|
|
|
|
2010-08-21 04:43:03 +00:00
|
|
|
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.
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param mixed $username Username
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function force_login($username)
|
|
|
|
{
|
|
|
|
// Complete the login
|
|
|
|
return $this->complete_login($username);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the stored password for a username.
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param mixed $username Username
|
2010-08-21 04:43:03 +00:00
|
|
|
* @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
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param string $password Password
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function check_password($password)
|
|
|
|
{
|
|
|
|
$username = $this->get_user();
|
|
|
|
|
|
|
|
if ($username === FALSE)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($password === $this->password($username));
|
|
|
|
}
|
|
|
|
|
2012-11-09 12:18:50 +00:00
|
|
|
} // End Auth File
|