php验证码登录博客,Laravel5+登录验证码 使用captcha方法

一、安装captchacomposer require mews/captcha

二、配置[/config/app.php]添加以下配置'providers' => [

// ...

Mews\Captcha\CaptchaServiceProvider::class,

]

'aliases' => [

// ...

'Captcha' => Mews\Captcha\Facades\Captcha::class,

]

三、生成自定义配置文件php artisan vendor:publish

运行之后,就可以在 config/captcha.php 中进行配置了。

四、使用 Captcha 为 auth 组件添加验证码功能

1、在登录视图中增加验证码的选项,可以加到密码和 remember me 之间/resources/views/auth/login.blade.php

验证码

@if($errors->has('captcha'))                  

{{$errors->first('captcha')}}

@endif          

              

2、重写AuthController 登录验证方法,并自定义提示信息: 修改 App\Http\Controllers\Auth\LoginController#首先要引入如下代码:use Illuminate\Http\Request;

#重写validateLogin方法:

#在验证里面加入验证码的规则验证即可/**

* DESC: 重写 AuthenticatesUsers 登录验证方法,并自定义提示信息;

* 原验证方法 Illuminate\Foundation\Auth\AuthenticatesUsers

* @param Request $request

*/

protected function validateLogin(Request $request){

$this->validate($request, [

$this->username() => 'required|string',

'password' => 'required|string'

'captcha' => 'required|captcha',

],[

'captcha.required' => '请填写验证码',

'captcha.captcha' => '验证码错误',

]);

}

完成后,刷新登录页面即可完成安装了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值