| <?php |
| /* |
| * Name: form_security.php |
| * Function: contains routines created to stop people from using 'bots' to auto complete the forms with spam info. |
| * I/O: functions take various parmaters, Some return values. |
| * By: M. Ward |
| * |
| */ |
| |
| /************************************** |
| * |
| * Name: SecureQuestion |
| * Function: This function generates a relatively random mathematical question and prints it to the bottom |
| * of the calling page. |
| * I/O: takes a param for where html output should go, and returns the 'result' of the question for comparison. |
| * Date: Nov 21/05 |
| * By: M. Ward |
| * |
| ***************************************/ |
| function SecureQuestion( &$html ) { |
| //get the 3 values and 2 functions |
| $Security_Values = array(mt_rand(1,100), mt_rand(1,100), mt_rand(1,100), mt_rand(0,1),mt_rand(0,1) ); |
| //sort out the operators |
| $Operators = array('+','-'); |
| |
| //set the entry form and question into the html output |
| $html .= "<tr><td colspan=\"2\"><font face=\"Arial\" color=\"#FF0000\">*</font>Please enter the result of the following Mathematical question: "; |
| $html .= $Security_Values[0] . $Operators[$Security_Values[3]] . $Security_Values[1] . $Operators[$Security_Values[4]] . $Security_Values[2]; |
| $html .= "<br /></td></tr> <tr><td colspan=\"2\"><input type=\"text\" size=\"6\" name=\"SkillAnswer\"></td></tr>"; |
| |
| //compute the result the hard way. |
| if ( $Security_Values[3] == 0) |
| $Result = $Security_Values[0] + $Security_Values[1]; |
| else |
| $Result = $Security_Values[0] - $Security_Values[1]; |
| if ( $Security_Values[4] == 0) |
| $Result = $Result + $Security_Values[2]; |
| else |
| $Result = $Result - $Security_Values[2]; |
| |
| |
| return( CryptResult($Result) ); |
| |
| } |
| |
| /********************************************* |
| * |
| * Name: CryptResult |
| * Function: encrypts(cheaply I might add) the passed int and returns the 'encrypted' result |
| * I/O: Takes the number to be encrypted and returns the encrypted data |
| * Date: Nov 23/05 |
| * By: M. Ward |
| * |
| * ********************************************/ |
| function CryptResult( $key ) { |
| |
| //first step |
| $crypt = $key - 83817; |
| //second step |
| $crypt = $crypt + 262237125; |
| |
| //now serialise the data |
| $crypt = serialize($crypt); |
| |
| //prep for storage |
| $crypt = base64_encode($crypt); |
| |
| //return value |
| return $crypt; |
| |
| } |
| |
| /********************************************* |
| * |
| * Name: DeCryptResult |
| * Function: Decrypts(cheaply I might add) the passed int and returns the 'clear' result |
| * I/O: Takes the number to be decrypted and returns the clear data |
| * Date: Nov 23/05 |
| * By: M. Ward |
| * |
| * ********************************************/ |
| function DecryptResult( $key ) { |
| |
| //first step decode |
| $clear= base64_decode($key); |
| //second step unserialize |
| $clear = unserialize($clear); |
| |
| //now backout the math |
| $clear = $clear - 262237125; |
| |
| //last step |
| $clear = $clear + 83817; |
| |
| //return value |
| return $clear; |
| |
| } |
| |
| |
| ?> |