AbstractPasswordHasher.php 1.9 KB

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