From: Roland Häder Date: Wed, 4 Jun 2008 11:17:17 +0000 (+0000) Subject: Password validator added, if emails mismatch the request will be rejected X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=25a5ed3ea49f6cd60d8163f220e021bc369f6791;p=shipsimu.git Password validator added, if emails mismatch the request will be rejected --- diff --git a/.gitattributes b/.gitattributes index f4232ff..ed5d93c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -329,6 +329,7 @@ inc/classes/main/filter/class_AbstractFilterDecorator.php -text inc/classes/main/filter/class_FilterChain.php -text inc/classes/main/filter/validator/.htaccess -text inc/classes/main/filter/validator/class_EmailValidatorFilter.php -text +inc/classes/main/filter/validator/class_PasswordValidatorFilter.php -text inc/classes/main/filter/validator/class_UserNameValidatorFilter.php -text inc/classes/main/helper/.htaccess -text inc/classes/main/helper/class_ -text diff --git a/inc/classes/main/filter/validator/class_EmailValidatorFilter.php b/inc/classes/main/filter/validator/class_EmailValidatorFilter.php index 37e207d..6c4f74b 100644 --- a/inc/classes/main/filter/validator/class_EmailValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_EmailValidatorFilter.php @@ -1,9 +1,9 @@ * @version 0.0.0 @@ -110,6 +110,15 @@ class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable { // Add a message to the response $responseInstance->addFatalMessage('email_taken'); + // Abort here + return false; + } elseif ($email1 != $email2) { + // Emails didn't match + $requestInstance->requestIsValid(false); + + // Add a message to the response + $responseInstance->addFatalMessage('emails_mismatch'); + // Abort here return false; } // END - elseif diff --git a/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php b/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php new file mode 100644 index 0000000..21d0941 --- /dev/null +++ b/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php @@ -0,0 +1,113 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class PasswordValidatorFilter extends BaseFrameworkSystem implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter for Password validation"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createPasswordValidatorFilter () { + // Get a new instance + $filterInstance = new PasswordValidatorFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get passwords + $password1 = $requestInstance->getRequestElement('pass1'); + $password2 = $requestInstance->getRequestElement('pass2'); + + // Is the password still not set? + if ((is_null($password1)) || (is_null($password2))) { + // Not found in form so stop the filtering process + $requestInstance->requestIsValid(false); + + // Add a message to the response + $responseInstance->addFatalMessage('password_unset'); + + // Abort here + return false; + } elseif ((empty($password1)) || (empty($password2))) { + // Password is empty + $requestInstance->requestIsValid(false); + + // Is the password empty? + if (empty($password1)) { + // Add a message to the response + $responseInstance->addFatalMessage('password1_empty'); + } // END - if + + // Is the confirmation empty? + if (empty($password2)) { + // Add a message to the response + $responseInstance->addFatalMessage('password2_empty'); + } // END - if + + // Abort here + return false; + } elseif ($password1 != $password2) { + // Passwords didn't match + $requestInstance->requestIsValid(false); + + // Add a message to the response + $responseInstance->addFatalMessage('passwords_mismatching'); + + // Abort here + return false; + } // END - elseif + } +} + +// [EOF] +?> diff --git a/inc/config.php b/inc/config.php index 0a92b9c..ac58e21 100644 --- a/inc/config.php +++ b/inc/config.php @@ -165,11 +165,14 @@ $cfg->setConfigEntry('file_input_stream', "FileIoStream"); // CFG: FILE-OUTPUT-STREAM $cfg->setConfigEntry('file_output_stream', "FileIoStream"); +// CFG: EMAIL-VALIDATOR +$cfg->setConfigEntry('email_validator', "EmailValidatorFilter"); + // CFG: USERNAME-VALIDATOR $cfg->setConfigEntry('username_validator', "UserNameValidatorFilter"); -// CFG: EMAIL-VALIDATOR -$cfg->setConfigEntry('email_validator', "EmailValidatorFilter"); +// CFG: PASSWORD-VALIDATOR +$cfg->setConfigEntry('password_validator', "PasswordValidatorFilter"); // [EOF] ?>