PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/symphony/lib/toolkit/cryptography/class.md5.php

https://github.com/vlad-ghita/symphony-2
PHP | 55 lines | 13 code | 3 blank | 39 comment | 1 complexity | fc53f93122eca34d94a8fc5f0dfcd027 MD5 | raw file
Possible License(s): BSD-3-Clause-No-Nuclear-License-2014
  1. <?php
  2. /**
  3. * @package cryptography
  4. */
  5. /**
  6. * MD5 is a cryptography class for hashing and comparing messages
  7. * using the MD5-Algorithm
  8. *
  9. * @since Symphony 2.3.1
  10. * @see toolkit.Cryptography
  11. * @deprecated This code is regarded as insecure and exists only for backwards-compatibility-purposes.
  12. * It should not be used when writing new password-related features.
  13. */
  14. Class MD5 extends Cryptography{
  15. /**
  16. * Uses `MD5` to create a hash based on some input
  17. *
  18. * @param string $input
  19. * the string to be hashed
  20. * @return string
  21. * the hashed string
  22. */
  23. public static function hash($input){
  24. Symphony::Log()->pushToLog('The use of MD5::hash() is discouraged due to severe security flaws.', E_DEPRECATED, true);
  25. return md5($input);
  26. }
  27. /**
  28. * Uses `MD5` to create a hash from the contents of a file
  29. *
  30. * @param string $input
  31. * the file to be hashed
  32. * @return string
  33. * the hashed string
  34. */
  35. public static function file($input){
  36. return md5_file($input);
  37. }
  38. /**
  39. * Compares a given hash with a cleantext password.
  40. *
  41. * @param string $input
  42. * the cleartext password
  43. * @param string $hash
  44. * the hash the password should be checked against
  45. * @param boolean $isHash
  46. * @return bool
  47. * the result of the comparison
  48. */
  49. public static function compare($input, $hash, $isHash=false){
  50. return ($hash == self::hash($input));
  51. }
  52. }