<?php
/**
 * @see Zend_Validate_Abstract
 */
require_once 'Zend/Validate/Abstract.php';


/**
 * @category   Malf
 * @package    Malf_Validate
 */

class Zend_Validate_MalfPasswordCheck extends Zend_Validate_Abstract
{
    /**
     * Validation failure message key for when the value given is already used by registered user
     */
    const PASS_NOT_MATCH = 'passwordsNotMatch';

    /**
     * Validation failure message template definitions
     *
     * @var array
     */
    protected $_messageTemplates = array(
        self::PASS_NOT_MATCH    => "Password and password check fields mismatch."
    );

    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if password and its check equals.
     *
     * @param  string $value
     * @return boolean
     */
    public function isValid($value, $context = null)
    {
        $value = (string) $value;
        $this->_setValue($value);

        if (is_array($context)) {
            if (isset($context['password_check'])
                && ($value == $context['password_chceck']))
            {
                return true;
            }
        } elseif (is_string($context) && ($value == $context)) {
            return true;
        }

        $this->_error(self::PASS_NOT_MATCH);
        return false;
    }
}