Remove hashing by default for user logins. Auth drivers are now in control of this...
[kohana-auth.git] / classes / kohana / auth / file.php
blobaa35174835adf49c5d99e532e284ab759ef45c19
1 <?php defined('SYSPATH') or die('No direct access allowed.');
2 /**
3 * File Auth driver.
4 * [!!] this Auth driver does not support roles nor autologin.
6 * @package Kohana/Auth
7 * @author Kohana Team
8 * @copyright (c) 2007-2010 Kohana Team
9 * @license http://kohanaframework.org/license
11 class Kohana_Auth_File extends Auth {
13 // User list
14 protected $_users;
16 /**
17 * Constructor loads the user list into the class.
19 public function __construct($config = array())
21 parent::__construct($config);
23 // Load user list
24 $this->_users = Arr::get($config, 'users', array());
27 /**
28 * Logs a user in.
30 * @param string username
31 * @param string password
32 * @param boolean enable autologin (not supported)
33 * @return boolean
35 protected function _login($username, $password, $remember)
37 if (is_string($password))
39 // Create a hashed password
40 $password = $this->hash($password);
43 if (isset($this->_users[$username]) AND $this->_users[$username] === $password)
45 // Complete the login
46 return $this->complete_login($username);
49 // Login failed
50 return FALSE;
53 /**
54 * Forces a user to be logged in, without specifying a password.
56 * @param mixed username
57 * @return boolean
59 public function force_login($username)
61 // Complete the login
62 return $this->complete_login($username);
65 /**
66 * Get the stored password for a username.
68 * @param mixed username
69 * @return string
71 public function password($username)
73 return Arr::get($this->_users, $username, FALSE);
76 /**
77 * Compare password with original (plain text). Works for current (logged in) user
79 * @param string $password
80 * @return boolean
82 public function check_password($password)
84 $username = $this->get_user();
86 if ($username === FALSE)
88 return FALSE;
91 return ($password === $this->password($username));
94 } // End Auth File