如何将验证码添加到Laravel 5.1登录?
如何将captcha/Google reCaptcha添加到用户身份验证登录?我只能修改注册的验证,如何修改登录的验证如何将验证码添加到Laravel 5.1登录?,laravel,laravel-5,laravel-5.1,Laravel,Laravel 5,Laravel 5.1,如何将captcha/Google reCaptcha添加到用户身份验证登录?我只能修改注册的验证,如何修改登录的验证 我的问题不是如何添加recaptcha,我的问题是如何将recaptcha验证添加到登录验证规则。您必须通过composer.json添加此库,然后编辑视图并将验证码代码放入其中 关于验证:您可以创建新规则并将其与Laravel validator集成,或者在Laravel验证之前或之后在controller中对其进行验证。您必须通过composer.json添加此库,然后编辑
我的问题不是如何添加recaptcha,我的问题是如何将recaptcha验证添加到登录验证规则。您必须通过composer.json添加此库,然后编辑视图并将验证码代码放入其中
关于验证:您可以创建新规则并将其与Laravel validator集成,或者在Laravel验证之前或之后在controller中对其进行验证。您必须通过composer.json添加此库,然后编辑视图并将验证码放入其中
关于验证:您可以创建新规则,并将其与Laravel validator集成,或者在Laravel验证之前或之后在控制器中对其进行验证。您可以为Laravel-5使用greggilbert/recaptcha包。这个github页面解释了如何使用这个包您可以为Laravel-5使用greggilbert/recaptcha包。这个github页面解释了如何使用这个包我就是这么想的,我从vendor/laravel/framework/src/illighte/Foundation/Auth/AuthenicatesUsers.php复制了postLogin方法,并对其进行了如下编辑:
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postLogin(\Illuminate\Http\Request $request)
{
$this->validate($request, [
$this->loginUsername() => 'required',
'password' => 'required',
'g-recaptcha-response' => 'required|recaptcha'
]);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
$throttles = $this->isUsingThrottlesLoginsTrait();
if ($throttles && $this->hasTooManyLoginAttempts($request)) {
return $this->sendLockoutResponse($request);
}
$credentials = $this->getCredentials($request);
if (\Auth::attempt($credentials, $request->has('remember'))) {
return $this->handleUserWasAuthenticated($request, $throttles);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
if ($throttles) {
$this->incrementLoginAttempts($request);
}
return redirect($this->loginPath())
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors([
$this->loginUsername() => $this->getFailedLoginMessage(),
]);
}
我已将方法param中的Request更改为\lighting\Http\Request,将Auth更改为\Auth。您可以在文件顶部添加这两个
然后我更改了登录的验证规则,并添加了“g-recaptcha-response”=>“required | recaptcha”以使用Google recaptcha,我就是这样理解的,我从vendor/laravel/framework/src/illighted/Foundation/Auth/AuthenicatesUsers.php复制了postLogin方法,并对其进行如下编辑:
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postLogin(\Illuminate\Http\Request $request)
{
$this->validate($request, [
$this->loginUsername() => 'required',
'password' => 'required',
'g-recaptcha-response' => 'required|recaptcha'
]);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
$throttles = $this->isUsingThrottlesLoginsTrait();
if ($throttles && $this->hasTooManyLoginAttempts($request)) {
return $this->sendLockoutResponse($request);
}
$credentials = $this->getCredentials($request);
if (\Auth::attempt($credentials, $request->has('remember'))) {
return $this->handleUserWasAuthenticated($request, $throttles);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
if ($throttles) {
$this->incrementLoginAttempts($request);
}
return redirect($this->loginPath())
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors([
$this->loginUsername() => $this->getFailedLoginMessage(),
]);
}
我已将方法param中的Request更改为\lighting\Http\Request,将Auth更改为\Auth。您可以在文件顶部添加这两个
然后,我更改了登录的验证规则,并添加了“g-recaptcha-response”=>“required | recaptcha”以使用Google recaptcha,以下是我的解决方法,对于其他也有此问题的人,请使用: 将validateLogin函数从vendor\laravel\framework\src\illights\Foundation\Auth\AuthenticatesUsers.php复制到app\http\Controllers\Auth\AuthController.php,然后将该行添加到数组中。你会得到这样的结果:
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
protected function validateLogin(\Illuminate\Http\Request $request)
{
$this->validate($request, [
$this->loginUsername() => 'required', 'password' => 'required','g-recaptcha-response' => 'required|recaptcha',
]);
}
就这样,验证码现在可以在登录表单上使用了。当然,您还应该在登录视图中添加{!!Recaptcha::render!!},以下是我的解决方法,对于其他也有此问题的用户,请使用: 将validateLogin函数从vendor\laravel\framework\src\illights\Foundation\Auth\AuthenticatesUsers.php复制到app\http\Controllers\Auth\AuthController.php,然后将该行添加到数组中。你会得到这样的结果:
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
protected function validateLogin(\Illuminate\Http\Request $request)
{
$this->validate($request, [
$this->loginUsername() => 'required', 'password' => 'required','g-recaptcha-response' => 'required|recaptcha',
]);
}
就这样,验证码现在可以在登录表单上使用了。当然,您还应该在登录视图中添加{!!Recaptcha::render!!}使用BotDetect-CAPTCHA
对于laravel 5.2:使用BotDetect验证码
对于laravel 5.2:转到vendor\laravel\ui\auth backend\AuthenticatesUsers.php并查找此函数,然后添加新规则:
public function validateLogin(Request $request)
{
$this->validate($request, [
$this->username() => 'required',
'password' => 'required',
// new rules here
'g-recaptcha-response' => 'required|captcha',
]);
}
转到vendor\laravel\ui\auth backend\AuthenticatesUsers.php并查找此函数,然后添加新规则:
public function validateLogin(Request $request)
{
$this->validate($request, [
$this->username() => 'required',
'password' => 'required',
// new rules here
'g-recaptcha-response' => 'required|captcha',
]);
}
这个图书馆?哪一个?你忘了链接,顺便说一句,google recaptcha的一个不错的软件包:这个库?哪一个?你忘了链接,顺便说一句,google recaptcha的一个不错的软件包:谢谢,我的问题不是如何验证,我的问题是在登录验证中添加验证码验证。谢谢,我的问题不是如何验证,我的问题是在登录验证中添加验证码验证。是的,覆盖AuthenticatesUsers文件中的validateLogin,快速解决方案。编辑供应商文件夹中的内容不是好做法,移动或上载Laravel项目时应忽略供应商文件夹,然后由composer在项目安装时重新下载是,覆盖AuthenticatesUsers文件中的validateLogin,快速解决方案。编辑供应商文件夹中的内容不是好做法,移动或上载Laravel项目时应忽略供应商文件夹,然后由composer在项目安装时重新下载。不幸的是,此包已被放弃。因此需要更新您的答案。不幸的是,此软件包已被放弃。因此需要更新您的答案。