当前位置:网站首页>Laravel文档阅读笔记-mews/captcha的使用(验证码功能)
Laravel文档阅读笔记-mews/captcha的使用(验证码功能)
2022-07-05 12:34:00 【IT1995】
这里用的是Laravel8。
这里验证码要使用到fileInfo的功能,需要提前让php加载此dll or so,在php.ini中修改:

验证码功能最终实现的效果是:

首先添加相关库:
composer require mews/captcha --ignore-platform-req=ext-fileinfo其次再生成对应的config文件:
php artisan vendor:publish输入你那边mews/captcha相关的选项:

我这里是选项11。
默认验证码为9位,这里太多了,看不清,修改下captcha.php
<?php
return [
'characters' => ['2', '3', '4', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'm', 'n', 'p', 'q', 'r', 't', 'u', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y', 'Z'],
'default' => [
'length' => 5,
'width' => 120,
'height' => 36,
'quality' => 90,
'math' => false,
'expire' => 60,
'encrypt' => false,
],
......
......
];这里default.length的大小本来是9的,我改成了5。
生成对应的Controller
php artisan make:controller CaptchaValidationController在CaptchaValidationController.php中生成验证码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class CaptchaValidationController extends Controller
{
public function reloadCaptcha()
{
return response()->json(['captcha'=> captcha_img()]);
}
}这里这个Controller就是验证码服务了。就完成了。
下面是使用。
前端:
JS相关:
<script type="text/javascript">
$('#captchaImg').click(function(){
$(this).prop('src',"{
{captcha_src()}}" + Math.random(1000,9999));
});
</script>HTML相关:
<div class="row">
<div class="col" style="max-width: 140px">
<img src="{
{ captcha_src() }}" id="captchaImg" >
</div>
<div class="col pull-left ">
<input type="text" autocomplete="off" placeholder="验证码" id="captcha" class="form-control" name="captcha">
</div>
</div>后端:
public function customLogin(Request $request)
{
$request->validate([
'email' => 'required|email',
'password' => 'required|min:6|max:128',
'captcha' => 'required|captcha'
]);
......
......
}这里Laravel自己做了处理,我们只要添加了captcha,就可以了。这里感觉比其他语言少写了好多逻辑判断代码。
边栏推荐
- [superhard core] is the core technology of redis
- Solve the problem of cache and database double write data consistency
- About cache exceptions: solutions for cache avalanche, breakdown, and penetration
- ZABBIX agent2 monitors mongodb nodes, clusters and templates (official blog)
- Database connection pool & jdbctemplate
- Detailed structure and code of inception V3
- Iterator details in list... Interview pits
- 从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
- Pytoch monolayer bidirectional_ LSTM implements MNIST and fashionmnist data classification
- ZABBIX agent2 monitors mongodb templates and configuration operations
猜你喜欢

I met Tencent in the morning and took out 38K, which showed me the basic smallpox

Kotlin variable

前几年外包干了四年,秋招感觉人生就这样了..

OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首

超高效!Swagger-Yapi的秘密

Constructing expression binary tree with prefix expression

Resnet+attention project complete code learning

Implementing Yang Hui triangle with cyclic queue C language

Redis highly available slice cluster

Preliminary exploration of basic knowledge of MySQL
随机推荐
《信息系统项目管理师》备考笔记---信息化知识
How to recover the information server and how to recover the server data [easy to understand]
Kotlin函数
About cache exceptions: solutions for cache avalanche, breakdown, and penetration
Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
struct MySQL
Making and using the cutting tool of TTF font library
研究:数据安全工具在 60% 的情况下无法抵御勒索软件
Experimental design - using stack to realize calculator
以VMware创新之道,重塑多云产品力
How to connect the API interface of Taobao open platform (super detailed)
JDBC exercise - query data encapsulated into object return & simple login demo
在家庭智能照明中应用的测距传感芯片4530A
Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
Deep discussion on the decoding of sent protocol
GPS data format conversion [easy to understand]
NPM install reports an error
Taobao flag insertion remarks | logistics delivery interface
Hexadecimal conversion summary
Distributed solution - completely solve website cross domain requests