PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/nooku/libraries/koowa/filter/md5.php

https://github.com/bhar1red/anahita
PHP | 45 lines | 16 code | 2 blank | 27 comment | 2 complexity | fc7ee08c35b92402b91814da3d1e781f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: md5.php 4628 2012-05-06 19:56:43Z johanjanssens $
  4. * @package Koowa_Filter
  5. * @copyright Copyright (C) 2007 - 2012 Johan Janssens. All rights reserved.
  6. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
  7. * @link http://www.nooku.org
  8. */
  9. /**
  10. * MD5 filter
  11. *
  12. * Validates or sanitizes an md5 hash (32 chars [a-f0-9])
  13. *
  14. * @author Johan Janssens <johan@nooku.org>
  15. * @package Koowa_Filter
  16. */
  17. class KFilterMd5 extends KFilterAbstract
  18. {
  19. /**
  20. * Validate a value
  21. *
  22. * @param scalar Variable to be validated
  23. * @return bool True when the variable is valid
  24. */
  25. protected function _validate($value)
  26. {
  27. $value = trim($value);
  28. $pattern = '/^[a-f0-9]{32}$/';
  29. return (is_string($value) && preg_match($pattern, $value) == 1);
  30. }
  31. /**
  32. * Sanitize a valaue
  33. *
  34. * @param scalar Variable to be sanitized
  35. * @return string
  36. */
  37. protected function _sanitize($value)
  38. {
  39. $value = trim(strtolower($value));
  40. $pattern = '/[^a-f0-9]*/';
  41. return substr(preg_replace($pattern, '', $value), 0, 32);
  42. }
  43. }