AbstractPasswordHasher.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * PHP 5
  4. *
  5. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice.
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://cakephp.org CakePHP(tm) Project
  14. * @since CakePHP(tm) v 2.4.0
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. /**
  18. * Abstract password hashing class
  19. *
  20. * @package Cake.Controller.Component.Auth
  21. */
  22. abstract class AbstractPasswordHasher {
  23. /**
  24. * Configurations for this object. Settings passed from authenticator class to
  25. * the constructor are merged with this property.
  26. *
  27. * @var array
  28. */
  29. protected $_config = array();
  30. /**
  31. * Constructor
  32. *
  33. * @param array $config Array of config.
  34. */
  35. public function __construct($config = array()) {
  36. $this->config($config);
  37. }
  38. /**
  39. * Get/Set the config
  40. *
  41. * @param array $config Sets config, if null returns existing config
  42. * @return array Returns configs
  43. */
  44. public function config($config = null) {
  45. if (is_array($config)) {
  46. $this->_config = array_merge($this->_config, $config);
  47. }
  48. return $this->_config;
  49. }
  50. /**
  51. * Generates password hash.
  52. *
  53. * @param string|array $password Plain text password to hash or array of data
  54. * required to generate password hash.
  55. * @return string Password hash
  56. */
  57. abstract public function hash($password);
  58. /**
  59. * Check hash. Generate hash from user provided password string or data array
  60. * and check against existing hash.
  61. *
  62. * @param string|array $password Plain text password to hash or data array.
  63. * @param string Existing hashed password.
  64. * @return boolean True if hashes match else false.
  65. */
  66. abstract public function check($password, $hashedPassword);
  67. }