芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/rentandbuyrealty.com/pennysave/application/app/Lib/Captcha.php
where('status', 1)->first(); return $reCaptcha ? $reCaptcha->generateScript() : null; } /** * Custom captcha script * * @return string */ public static function customCaptcha($width = '100%', $height = 46, $bgColor = '#003'){ $textColor = '#'.gs()->base_color; $captcha = Extension::where('act', 'custom-captcha')->where('status', 1)->first(); if (!$captcha) { return 0; } $code = rand(100000, 999999); $char = str_split($code); $ret = '
'; $ret .= '
'; foreach ($char as $value) { $ret .= '
' . $value . '
'; } $ret .= '
'; $captchaSecret = hash_hmac('sha256', $code, $captcha->shortcode->random_key->value); $ret .= '
'; return $ret; } /** * Verify all captcha * * @return boolean */ public static function verify(){ $gCaptchaPass = self::verifyGoogleCaptcha(); $cCaptchaPass = self::verifyCustomCaptcha(); if ($gCaptchaPass && $cCaptchaPass) { return true; } return false; } /** * Verify google recaptcha2 * * @return boolean */ public static function verifyGoogleCaptcha(){ $pass = true; $googleCaptcha = Extension::where('act', 'google-recaptcha2')->where('status', 1)->first(); if ($googleCaptcha) { $resp = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$googleCaptcha->shortcode->secret_key->value."&response=".request()['g-recaptcha-response']."&remoteip=".getRealIP()), true); if (!$resp['success']) { $pass = false; } } return $pass; } /** * Verify custom captcha * * @return boolean */ public static function verifyCustomCaptcha(){ $pass = true; $customCaptcha = Extension::where('act', 'custom-captcha')->where('status', 1)->first(); if ($customCaptcha) { $captchaSecret = hash_hmac('sha256', request()->captcha, $customCaptcha->shortcode->random_key->value); if ($captchaSecret != request()->captcha_secret) { $pass = false; } } return $pass; } }