class_GraphicalCodeCaptchaVerifierFilter.php

Go to the documentation of this file.
00001 <?php
00024 class GraphicalCodeCaptchaVerifierFilter extends BaseFilter implements Filterable {
00030         protected function __construct () {
00031                 // Call parent constructor
00032                 parent::__construct(__CLASS__);
00033         }
00034 
00040         public final static function createGraphicalCodeCaptchaVerifierFilter () {
00041                 // Get a new instance
00042                 $filterInstance = new GraphicalCodeCaptchaVerifierFilter();
00043 
00044                 // Return the instance
00045                 return $filterInstance;
00046         }
00047 
00055         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
00056                 // Get the captcha code
00057                 $captchaCode = $requestInstance->getRequestElement('c_code');
00058 
00059                 // Is this set?
00060                 if (is_null($captchaCode)) {
00061                         // Not set so request is invalid
00062                         $requestInstance->requestIsValid(false);
00063 
00064                         // Add fatal message
00065                         $responseInstance->addFatalMessage('captcha_code_unset');
00066 
00067                         // Skip further processing
00068                         return false;
00069                 } elseif (empty($captchaCode)) {
00070                         // Empty value so request is invalid
00071                         $requestInstance->requestIsValid(false);
00072 
00073                         // Add fatal message
00074                         $responseInstance->addFatalMessage('captcha_code_empty');
00075 
00076                         // Skip further processing
00077                         return false;
00078                 }
00079 
00080                 // Get the hash as well
00081                 $captchaHash = $requestInstance->getRequestElement('hash');
00082 
00083                 // Is this set?
00084                 if (is_null($captchaHash)) {
00085                         // Not set so request is invalid
00086                         $requestInstance->requestIsValid(false);
00087 
00088                         // Add fatal message
00089                         $responseInstance->addFatalMessage('captcha_hash_unset');
00090 
00091                         // Skip further processing
00092                         return false;
00093                 } elseif (empty($captchaHash)) {
00094                         // Empty value so request is invalid
00095                         $requestInstance->requestIsValid(false);
00096 
00097                         // Add fatal message
00098                         $responseInstance->addFatalMessage('captcha_hash_empty');
00099 
00100                         // Skip further processing
00101                         return false;
00102                 }
00103 
00104                 // Now, both are set hash the given one. First get a crypto instance
00105                 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
00106 
00107                 // Then hash the code
00108                 $hashedCode = $cryptoInstance->hashString($captchaCode, $captchaHash);
00109 
00110                 // Is this CAPTCHA valid?
00111                 if ($hashedCode != $captchaHash) {
00112                         // Not the same so request is invalid
00113                         $requestInstance->requestIsValid(false);
00114 
00115                         // Add fatal message
00116                         $responseInstance->addFatalMessage('captcha_hash_mismatch');
00117                 } // END - not the same!
00118         }
00119 }
00120 
00121 // [EOF]
00122 ?>

Generated on Mon Dec 8 01:06:45 2008 for Ship-Simulator by  doxygen 1.5.6