]> git.mxchange.org Git - shipsimu.git/commitdiff
Password validator added, if emails mismatch the request will be rejected
authorRoland Häder <roland@mxchange.org>
Wed, 4 Jun 2008 11:17:17 +0000 (11:17 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 4 Jun 2008 11:17:17 +0000 (11:17 +0000)
.gitattributes
inc/classes/main/filter/validator/class_EmailValidatorFilter.php
inc/classes/main/filter/validator/class_PasswordValidatorFilter.php [new file with mode: 0644]
inc/config.php

index f4232ff3815ea537c85e6401fb66d6355fa50cf3..ed5d93cb80f60c591cba78af3636b0b0bb83f260 100644 (file)
@@ -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
index 37e207d7b373a8abe83f317594f04fec419af862..6c4f74bb689497db9e0366c015ba6dbde4972c04 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /**
  * A concrete filter for validating the email address. This filter may intercept
- * the filter chain if no email address is given or if the supplied username has
- * an invalid form. It could also intercept the filter chain if the email
- * address is already used by some one if configuration requires this.
+ * the filter chain if no email address is given or if the supplied email has an
+ * invalid form. It could also intercept the filter chain if the email address
+ * is already used by some one if configuration requires this.
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @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 (file)
index 0000000..21d0941
--- /dev/null
@@ -0,0 +1,113 @@
+<?php
+/**
+ * A concrete filter for validating the password. This filter may intercept
+ * the filter chain if no password is given or if both passwords didn't match.
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 0a92b9c8c184a66ce060c99e6a743fe0590174c7..ac58e21524047710d9140b5b102427a002062494 100644 (file)
@@ -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]
 ?>