当前位置:网站首页>Laravel admin login add graphic verification code
Laravel admin login add graphic verification code
2022-06-26 11:06:00 【siner. li】
introduce
composer require mews/captcha
modify
config/app.php
'providers' => [
// ...
Mews\Captcha\CaptchaServiceProvider::class,
]
'aliases' => [
// ...
'Captcha' => Mews\Captcha\Facades\Captcha::class,
]
php artisan vendor:publish
modify
config/captcha.php Medium default
return [
'default' => [
'length' => 5,
'width' => 120,
'height' => 36,
'quality' => 90,
],
// ...
];
Modify the login method
modify app/Admin/Controllers/AuthController.php , If not, copy vendor/encore/laravel-admin/src/Controllers/AuthController.php To app/Admin/Controllers/AuthController.php
example :
<?php
namespace App\Admin\Controllers;
use Encore\Admin\Controllers\AuthController as BaseAuthController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Validator;
class AuthController extends BaseAuthController
{
public function getLogin()
{
if (!Auth::guard('admin')->guest()) {
return redirect(config('admin.route.prefix'));
}
return view('admin.login');
}
public function postLogin(Request $request)
{
$credentials = $request->only(['username', 'password','captcha']);
$validator = Validator::make($credentials, [
'username' => 'required',
'password' => 'required',
'captcha' => 'required|captcha'
]);
if ($validator->fails()) {
return Redirect::back()->withInput()->withErrors($validator);
}
unset($credentials['captcha']);
if (Auth::guard('admin')->attempt($credentials)) {
admin_toastr(trans('admin.login_successful'));
return redirect()->intended(config('admin.route.prefix'));
}
return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);
}
protected function getFailedLoginMessage()
{
return Lang::has('auth.failed')
? trans('auth.failed')
: 'These credentials do not match our records.';
}
}
Modify page
Copy vendor/encore/laravel-admin/resources/views/login.blade.php To resources/views/admin/login.blade.php Add code between password and remember my code block
example :
<div class="form-group has-feedback {!! !$errors->has('password') ?: 'has-error' !!}">
@if($errors->has('password'))
@foreach($errors->get('password') as $message)
<label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{
{
$message}}</label><br>
@endforeach
@endif
<input type="password" class="form-control" placeholder="{
{ trans('admin.password') }}" name="password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<!-- Add code here start-->
<div class="row">
<div class="form-group has-feedback {!! !$errors->has('captcha') ?: 'has-error' !!}">
@if($errors->has('captcha'))
@foreach($errors->get('captcha') as $message)
<label class="control-label" for="inputError" style="margin-left: 15px"><i class="fa fa-times-circle-o">{
{
$message}}</i></label></br>
@endforeach
@endif
<input type="text" class="form-control" style="display: inline;width: 55%; margin-left: 15px" placeholder="{
{ trans('admin.captcha') }}" name="captcha">
<span class="glyphicon glyphicon-refresh form-control-feedback captcha" style="right:39%;z-index: 100"></span>
<img class="captcha" src="{
{ captcha_src('admin') }}">
</div>
</div>
<!-- Add code here end-->
<div class="row">
<div class="col-xs-8">
@if(config('admin.auth.remember'))
边栏推荐
- Easyx----- C language implementation 2048
- That is to say, "live broadcast" is launched! One stop live broadcast service with full link upgrade
- wangEditor 上传本地视频修改
- Linux下安裝Mysql【詳細】
- Grain Mall - distributed Foundation
- PC QQ大廳 上傳更新 修改versionInfo
- PC QQ大厅 上传更新 修改versionInfo
- SQL Server foundation introduction collation
- 栖霞市住建局和消防救援大队开展消防安全培训
- 近期工作汇报
猜你喜欢

【北邮果园微处理器设计】10 Serial Communication 串口通信笔记

滑动窗口
![[deep learning theory] (7) long and short term memory network LSTM](/img/fb/57781998390e0722df68e6c2e49098.gif)
[deep learning theory] (7) long and short term memory network LSTM

2021 Q3-Q4 Kotlin Multiplatform 使用现状 | 调查报告

9、 Beautify tables, forms, and hyperlinks

OpenCV图像处理-灰度处理

Getting started with postman

Docker中实现MySQL主从复制

Query online users and forced withdrawal users based on oauth2

redux相关用法
随机推荐
Easyx-----c语言实现2048
Sqli-labs靶场1-5
MySQL Performance Monitoring and SQL statements
Detailed explanation of MySQL fuzzy query
Work report (2)
PC QQ hall upload update modify VersionInfo
Consumer microservice Governance Center stepping on the pit
ceph运维常用指令
JWT (SSO scheme) + three ways of identity authentication
机器学习LDA——实验报告
Matrix fast power notes
工作汇报(3)
Oracle11g reports an error when starting the database ora-27154: post/wait create failed
深度理解STM32的串口实验(寄存器)【保姆级教程】
jwt认证协议阐述之——我开了一家怡红院
滑动窗口
栖霞市住建局和消防救援大队开展消防安全培训
Machine learning LDA - Experimental Report
Bit operation n & (n-1), leetcode231, interview question 05.06
mysql性能监控和sql语句