<?php

/**
 * PasswordValidator
 * 
 * Validates user input, ensuring password and password
 * confirmation are equal.
 *
 * @version DR1.6
 */
class PasswordValidator extends LengthValidator {



	protected $confirmation;



	/**
	 * Constructs a PasswordValidator instance
	 * 
	 * @param value : the user input to be validated
	 * @param view : the View where any error shall be posted
	 * @param confirmation : the password confirmation
	 * @param minLength : the minimum acceptable length
	 * @param maxLength : the maximum acceptable length
	 */
	public function __construct($value, IReadableView $view, $confirmation, $minLength = 1, $maxLength = 0) {
		parent::__construct($value, $view, $minLength, $maxLength);
		$this->confirmation = $confirmation;
	}



	/**
	 * Validates user input, ensuring password and password
	 * confirmation are equal.
	 * 
	 * @return true if password and confirmation are equal and 
	 * their length is comprised within minLength and maxLength.
	 */
	public function valid() {
		// Always check parent validity first
		if (!parent::valid()) {
			return false;
		}
		// The password and confirmation must be equal
		if ($this->value != $this->confirmation) {
			$this->view->errorMessage(__('Check password confirmation'));
			return false;
		}
		// Password is valid
		return true;
	}



} // PasswordValidator

?>