StoreObject( 'captcha_' . $key, $strCaptcha, $nTimeout ); return $strCaptcha; } public static function BValidateCaptcha( $key, $strCaptchaAttempt ) { return self::EValidateCaptcha( $key, $strCaptchaAttempt ) == k_EResultOK; } public static function EValidateCaptcha( $key, $strCaptchaAttempt ) { $strCaptchaAttempt = strtoupper( $strCaptchaAttempt ); $strLockKey = 'captcha_lock_' . $key; if ( !GetSharedObjectCache()->BLock( $strLockKey, 2 ) ) return k_EResultLockingFailed; $strCaptcha = GetSharedObjectCache()->GetObject( 'captcha_' . $key ); GetSharedObjectCache()->BDelete( 'captcha_' . $key ); GetSharedObjectCache()->BUnlock( $strLockKey ); if ( empty( $strCaptcha ) ) { return k_EResultTimeout; } if ( strlen( $strCaptcha ) != self::CAPTCHA_LENGTH ) { return k_EResultUnexpectedError; } if ( strcmp( $strCaptcha, $strCaptchaAttempt ) === 0 ) return k_EResultOK; else return k_EResultNoMatch; } public static function EValidateRecaptcha( $strCaptchaResponse, $strRemoteIP ) { $response = curl_url_fetch( "https://www.google.com/recaptcha/api/siteverify?secret=6LdlRgATAAAAAJPeL4w-IsD_fxhh4iY2VUfAyZVS&response=" . urlencode( $strCaptchaResponse ) . "&remoteip=" . urlencode( $strRemoteIP) ); if ( empty($response) ) { return k_EResultRemoteCallFailed; } $jsonResponse = json_decode( $response ); if ( empty($jsonResponse) ) { return k_EResultBadResponse; } return $jsonResponse->success ? k_EResultOK : k_EResultFail; } public static function RenderCaptchaForString( $strCaptcha ) { $width = 206; $height = 40; $rectangles = rand( 3, 4 ); $yvariance = 3; $minwidth = 24; $maxwidth = 27; $anglevariance = 12; // the hex code broken down - #67c1f5 $fgR = 0x67 / 0xff; $fgG = 0xc1 / 0xff; $fgB = 0xf5 / 0xff; // #131f2f $bgR = 0x13 / 0xff; $bgG = 0x1f / 0xff; $bgB = 0x2f / 0xff; $fonts = Array(); $fonts[] = realpath( dirname( __FILE__ ) ) . '/resources/arial.ttf'; $fonts[] = realpath( dirname( __FILE__ ) ) . '/resources/comic.ttf'; $fonts[] = realpath( dirname( __FILE__ ) ) . '/resources/tahoma.ttf'; $fontsize = 18; // Create image and draw basic background $image = imagecreatetruecolor( $width, $height ); $shade = 150; $bgcolor = imagecolorallocate( $image, $shade * $bgR, $shade * $bgG, $shade * $bgB ); imagefilledrectangle( $image, 0, 0, $width, $height, $bgcolor ); // Draw some random rectangles (wide ones) for( $i = 0; $i < $rectangles; ++$i ) { $shade = rand( 100, 140 ); $color = imagecolorallocatealpha( $image, $shade* $fgR, $shade* $fgG, $shade* $fgB, rand( 30, 60 ) ); $ypos0 = rand( 0, $height ); $xpos0 = rand( 0, $width ); $ypos1 = $ypos0 + rand( -$height/8, $height/8 ); $xpos1 = $xpos0 + rand( -$width/6, $width/6 ); imagefilledrectangle( $image, min( $xpos0, $xpos1 ), min( $ypos0, $ypos1 ), max( $xpos0, $xpos1 ), max( $ypos0, $ypos1 ), $color ); } // Again, but ones that are tall this time for( $i = 0; $i < $rectangles; ++$i ) { $shade = rand( 100, 140 ); $color = imagecolorallocatealpha( $image, $shade * $fgR, $shade* $fgG, $shade* $fgB, rand( 30, 60 ) ); $ypos0 = rand( 0, $height/2 ); $xpos0 = rand( 0, $width/2 ); $ypos1 = $ypos0 + rand( -$height/1.5, $height/1.5 ); $xpos1 = $xpos0 + rand( -$width/15, $width/15 ); imagefilledrectangle( $image, min( $xpos0, $xpos1 ), min( $ypos0, $ypos1 ), max( $xpos0, $xpos1 ), max( $ypos0, $ypos1 ), $color ); } // Set thickness for line drawing used below imagesetthickness( $image, 1.2 ); // Draw Text $x = rand( 20, 50 ); $y = 30; for( $i=0; $i