├── README.md ├── composer.json ├── previews └── preview.png └── src ├── ServiceProvider.php ├── SimpleCaptcha.php └── helpers.php /README.md: -------------------------------------------------------------------------------- 1 |
A simple laravel captcha package
10 | 11 |  12 | 13 | 14 | ## Features 15 | - Lightweight 16 | - Simple & easy to use 17 | - Support Laravel version >= 5 18 | - Captcha validation rules 19 | - Customizable 20 | 21 | ## Documentation 22 | Get full documentation of [Laravel Simple Captcha](https://laravelarticle.com/laravel-simple-captcha) 23 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "haruncpi/laravel-simple-captcha", 3 | "description": "A laravel simple captcha package", 4 | "license": "cc-by-4.0", 5 | "keywords": [ 6 | "laravel", 7 | "simple", 8 | "captcha" 9 | ], 10 | "type": "library", 11 | "authors": [ 12 | { 13 | "name": "MD.HARUN-UR-RASHID", 14 | "email": "harun.cox@gmail.com" 15 | } 16 | ], 17 | "minimum-stability": "dev", 18 | "prefer-stable": true, 19 | "require": { 20 | "php": ">=5.6" 21 | }, 22 | "autoload": { 23 | "files": [ 24 | "src/helpers.php" 25 | ], 26 | "psr-4": { 27 | "Haruncpi\\LaravelSimpleCaptcha\\": "src" 28 | } 29 | }, 30 | "scripts": { 31 | "phpunit": "phpunit" 32 | }, 33 | "extra": { 34 | "laravel": { 35 | "providers": [ 36 | "Haruncpi\\LaravelSimpleCaptcha\\ServiceProvider" 37 | ] 38 | } 39 | }, 40 | "config": { 41 | "preferred-install": "dist", 42 | "sort-packages": true, 43 | "optimize-autoloader": true 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /previews/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haruncpi/laravel-simple-captcha/af4f7c6773225d7be159c02c2befa0abff480bf4/previews/preview.png -------------------------------------------------------------------------------- /src/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | num1 = rand(2, 5); 17 | $this->num2 = rand(6, 9); 18 | $this->actionNumber = rand(1, 3); 19 | 20 | $this->arr['num1'] = $this->num1; 21 | $this->arr['num2'] = $this->num2; 22 | 23 | switch ($this->actionNumber) { 24 | case 1: 25 | $this->arr['question'] = $this->num1 . " + " . $this->num2 . " = ? "; 26 | $this->arr['answer'] = $this->addition($this->num1, $this->num2); 27 | break; 28 | 29 | case 2: 30 | $this->arr['question'] = $this->num2 . " - " . $this->num1 . " = ? "; 31 | $this->arr['answer'] = $this->subtraction($this->num1, $this->num2); 32 | break; 33 | 34 | case 3: 35 | $this->arr['question'] = $this->num1 . " x " . $this->num2 . " = ? "; 36 | $this->arr['answer'] = $this->multiplication($this->num1, $this->num2); 37 | break; 38 | } 39 | 40 | return $this->arr; 41 | } 42 | 43 | private function addition($num1, $num2) 44 | { 45 | return $num1 + $num2; 46 | } 47 | 48 | private function subtraction($num1, $num2) 49 | { 50 | return $num2 - $num1; 51 | } 52 | 53 | private function multiplication($num1, $num2) 54 | { 55 | return $num1 * $num2; 56 | } 57 | 58 | 59 | public static function getQuestion() 60 | { 61 | $instance = new self(); 62 | Session::put($instance->sessionKey, $instance->generate()); 63 | 64 | return Session::get($instance->sessionKey)['question']; 65 | } 66 | 67 | public static function getAnswer() 68 | { 69 | $instance = new self(); 70 | return Session::get($instance->sessionKey)['answer']; 71 | } 72 | } -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 |