当前位置:网站首页>Laravel document reading notes -mews/captcha use (verification code function)
Laravel document reading notes -mews/captcha use (verification code function)
2022-07-05 12:58:00 【IT1995】
It's used here Laravel8.
The verification code here should be used to fileInfo The function of , Need to give in advance php Load this dll or so, stay php.ini Revision in China :

The final effect of the verification code function is :

First, add related libraries :
composer require mews/captcha --ignore-platform-req=ext-fileinfoThen generate the corresponding config file :
php artisan vendor:publishEnter your side mews/captcha Related options :

Here are the options 11.
The default verification code is 9 position , There's too much here , Can't see , Modify the 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,
],
......
......
];here default.length The size of was originally 9 Of , I changed it to 5.
Generate corresponding Controller
php artisan make:controller CaptchaValidationControllerstay CaptchaValidationController.php Generate verification code in :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class CaptchaValidationController extends Controller
{
public function reloadCaptcha()
{
return response()->json(['captcha'=> captcha_img()]);
}
}Here it is. Controller It's the verification code service . It's done. .
Here's how to use .
front end :
JS relevant :
<script type="text/javascript">
$('#captchaImg').click(function(){
$(this).prop('src',"{
{captcha_src()}}" + Math.random(1000,9999));
});
</script>HTML relevant :
<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=" Verification Code " id="captcha" class="form-control" name="captcha">
</div>
</div>Back end :
public function customLogin(Request $request)
{
$request->validate([
'email' => 'required|email',
'password' => 'required|min:6|max:128',
'captcha' => 'required|captcha'
]);
......
......
}here Laravel I handled it myself , We just add captcha, That's all right. . I feel that there is a lot less logic judgment code than other languages .
边栏推荐
- Reshape the power of multi cloud products with VMware innovation
- Principle and performance analysis of lepton lossless compression
- 【Nacos云原生】阅读源码第一步,本地启动Nacos
- 石臻臻的2021总结和2022展望 | 文末彩蛋
- Four common problems of e-commerce sellers' refund and cash return, with solutions
- 实战模拟│JWT 登录认证
- 研究:数据安全工具在 60% 的情况下无法抵御勒索软件
- A deep long article on the simplification and acceleration of join operation
- 自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类
- Volatile instruction rearrangement and why instruction rearrangement is prohibited
猜你喜欢

Tips and tricks of image segmentation summarized from 39 Kabul competitions

Super efficient! The secret of swagger Yapi

Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue

DNS的原理介绍

Volatile instruction rearrangement and why instruction rearrangement is prohibited

Why is your next computer a computer? Explore different remote operations

开发者,云原生数据库是未来吗?

ActiveMQ installation and deployment simple configuration (personal test)

百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程

Transactions from December 27 to 28, 2021
随机推荐
Taobao short videos are automatically released in batches without manual RPA open source
Docker configures redis and redis clusters
Laravel文档阅读笔记-mews/captcha的使用(验证码功能)
函数的默认参数&函数参数的多种方法
从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
Kotlin process control and circulation
Association modeling method in SAP segw transaction code
#yyds干货盘点#js截取文件后缀名
【云原生】Nacos-TaskManager 任务管理的使用
Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
#yyds干货盘点# 解决名企真题:搬圆桌
在家庭智能照明中应用的测距传感芯片4530A
自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类
HiEngine:可媲美本地的云原生内存数据库引擎
Overflow toolbar control in SAP ui5 view
以VMware创新之道,重塑多云产品力
Principle and performance analysis of lepton lossless compression
Using docker for MySQL 8.0 master-slave configuration
SAP UI5 FlexibleColumnLayout 控件介绍
CVPR 2022 | single step 3D target recognizer based on sparse transformer