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

/libraries/koowa/filter/md5.php

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