*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule UserPassword * * Check value against current user's password * * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_StrongPassword extends WBPAT_Forms_Rule { /** * Initialize validation codes using gettext * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('wombat', 'Password must be at least five characters long.'), 2 => patI18n::dgettext('wombat', 'Weak password detected. Password must contain letters and digits, at least.') ); return true; } /** * apply rule * * @param patForms_Element form object */ public function applyRule(&$element, $type = PATFORMS_RULE_AFTER_VALIDATION) { $value = $element->getValue(); if (strlen($value) < 5) { $this->addValidationError(1); return false; } // password must have letters, digits and something different $letter = preg_match('/[a-z]/i', $value); $digit = preg_match('/\d/', $value); //$else = preg_match('/[^a-z^A-Z^0-9]/', $value); $else = true; if ($letter && $digit && $else) { return true; } $this->addValidationError(2); return false; } } ?>