File.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.
  5. *
  6. * @package Kohana/Auth
  7. * @author Kohana Team
  8. * @copyright (c) 2007-2017 Kohana Team
  9. * @license https://koseven.ga/LICENSE.md
  10. */
  11. class Kohana_Auth_File extends Auth {
  12. // User list
  13. protected $_users;
  14. /**
  15. * Constructor loads the user list into the class.
  16. */
  17. public function __construct($config = array())
  18. {
  19. parent::__construct($config);
  20. // Load user list
  21. $this->_users = Arr::get($config, 'users', array());
  22. }
  23. /**
  24. * Logs a user in.
  25. *
  26. * @param string $username Username
  27. * @param string $password Password
  28. * @param boolean $remember Enable autologin (not supported)
  29. * @return boolean
  30. */
  31. protected function _login($username, $password, $remember)
  32. {
  33. if (is_string($password))
  34. {
  35. // Create a hashed password
  36. $password = $this->hash($password);
  37. }
  38. if (isset($this->_users[$username]) AND $this->_users[$username] === $password)
  39. {
  40. // Complete the login
  41. return $this->complete_login($username);
  42. }
  43. // Login failed
  44. return FALSE;
  45. }
  46. /**
  47. * Forces a user to be logged in, without specifying a password.
  48. *
  49. * @param mixed $username Username
  50. * @return boolean
  51. */
  52. public function force_login($username)
  53. {
  54. // Complete the login
  55. return $this->complete_login($username);
  56. }
  57. /**
  58. * Get the stored password for a username.
  59. *
  60. * @param mixed $username Username
  61. * @return string
  62. */
  63. public function password($username)
  64. {
  65. return Arr::get($this->_users, $username, FALSE);
  66. }
  67. /**
  68. * Compare password with original (plain text). Works for current (logged in) user
  69. *
  70. * @param string $password Password
  71. * @return boolean
  72. */
  73. public function check_password($password)
  74. {
  75. $username = $this->get_user();
  76. if ($username === FALSE)
  77. {
  78. return FALSE;
  79. }
  80. return ($password === $this->password($username));
  81. }
  82. } // End Auth File