PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/PasswordLib/Password/Implementation/MD5.php

http://github.com/ircmaxell/PHP-PasswordLib
PHP | 54 lines | 15 code | 7 blank | 32 comment | 1 complexity | d514d886be1227a2d4c0b5390da12768 MD5 | raw file
  1. <?php
  2. /**
  3. * The Blowfish password hashing implementation
  4. *
  5. * Use this class to generate and validate Blowfish password hashes.
  6. *
  7. * PHP version 5.3
  8. *
  9. * @category PHPPasswordLib
  10. * @package Password
  11. * @subpackage Implementation
  12. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  13. * @copyright 2011 The Authors
  14. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  15. * @version Build @@version@@
  16. */
  17. namespace PasswordLib\Password\Implementation;
  18. use PasswordLib\Random\Factory as RandomFactory;
  19. /**
  20. * The Blowfish password hashing implementation
  21. *
  22. * Use this class to generate and validate Blowfish password hashes.
  23. *
  24. * @category PHPPasswordLib
  25. * @package Password
  26. * @subpackage Implementation
  27. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  28. */
  29. class MD5 extends Crypt {
  30. protected static $prefix = '$1$';
  31. protected $saltLen = 12;
  32. /**
  33. * Determine if the hash was made with this method
  34. *
  35. * @param string $hash The hashed data to check
  36. *
  37. * @return boolean Was the hash created by this method
  38. */
  39. public static function detect($hash) {
  40. static $regex = '/^\$1\$[a-zA-Z0-9.\/]{8}\$[a-zA-Z0-9.\/]{22}/';
  41. return 1 == preg_match($regex, $hash);
  42. }
  43. protected function generateSalt() {
  44. $salt = parent::generateSalt();
  45. return '$1$' . $salt;
  46. }
  47. }