*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule UserPassword * * Check value against current user's password * * @version 0.2.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_UserPassword 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', 'User not logged in'), 2 => patI18n::dgettext('wombat', 'Current password does not match') ); return true; } /** * method called by patForms or any patForms_Element to validate the * element or the form. * * @param patForms_Element form object */ public function applyRule( &$element, $type = PATFORMS_RULE_AFTER_VALIDATION ) { $pwd = $element->getValue(); if( empty( $pwd ) ) { $this->addValidationError( 2 ); return false; } WBClass::load( 'WBUser_Auth' ); $user = WBUser_Auth::getCurrent(); if (!$user->isAuthenticated()) { $this->addValidationError(1); return false; } $data = $user->getData(); $storage = $user->getStorageModule(); $crypted = $storage->getPasswordHash($pwd); if ($crypted != $data['password']) { $this->addValidationError(2); return false; } return true; } }