PageRenderTime 51ms CodeModel.GetById 20ms app.highlight 1ms RepoModel.GetById 29ms 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
 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/**
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 * @package     Koowa_Filter
17 */
18class KFilterMd5 extends KFilterAbstract
19{
20    /**
21     * Validate a value
22     *
23     * @param   scalar  Variable to be validated
24     * @return  bool    True when the variable is valid
25     */
26    protected function _validate($value)
27    {
28        $value = trim($value);
29        $pattern = '/^[a-f0-9]{32}$/';
30        return (is_string($value) && preg_match($pattern, $value) == 1);
31    }
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}