43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Mews\Captcha\Captcha;
|
|
|
|
class CaptchaController extends Controller
|
|
{
|
|
/**
|
|
* Generate a new captcha image and return the HTML code.
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function reload()
|
|
{
|
|
// Konfigurasi captcha
|
|
$config = [
|
|
'length' => 4, // Panjang captcha
|
|
'width' => 120, // Lebar captcha
|
|
'height' => 36, // Tinggi captcha
|
|
'quality' => 90, // Kualitas gambar
|
|
'math' => true, // Gunakan operasi matematika, true atau false
|
|
];
|
|
|
|
// Inisialisasi Captcha dengan konfigurasi
|
|
$captcha = new Captcha($config);
|
|
|
|
// Generate new captcha image
|
|
$captchaData = $captcha->create();
|
|
|
|
// Encrypt the captcha code for verification
|
|
$encryptedCaptcha = Crypt::encryptString($captchaData['sensitive']);
|
|
|
|
// Return the HTML code for the new captcha image
|
|
return response()->json([
|
|
'captcha' => $captchaData['image_src'],
|
|
'encrypted_captcha' => $encryptedCaptcha,
|
|
]);
|
|
}
|
|
}
|