laravel5.7验证码并验证登录

﹏ヽ暗。殇╰゛Y 2022-03-17 16:26 353阅读 0赞

跑验证码第三方包

  1. composer require mews/captcha

config/app.php进行配置

‘providers’ => [
// …
Mews\Captcha\CaptchaServiceProvider::class,
]

‘aliases’ => [
// …
‘Captcha’ => Mews\Captcha\Facades\Captcha::class,
]

跑命令 php artisan vendor:publish 进行自定义验证码规则

前端使用

  1. <div class="am-form-group">
  2. <label>验证码:</label>
  3. <input type="text" class="tpl-form-input" name="captcha" placeholder="请输入验证码">
  4. <div style="margin-left: 10px;">
  5. <img src="{
  6. { captcha_src('flat') }}" style="cursor: pointer" onclick="this.src='{
  7. {captcha_src('flat')}}&'+Math.random()" >//captcha_src('flat')是应用flat规则不填为默认
  8. </div>
  9. </div>

后台验证

  1. protected function validateLogin(Request $request)
  2. {
  3. $request->validate([
  4. 'captcha' => 'required|captcha',
  5. $this->username() => 'required|string',
  6. 'password' => 'required|string',
  7. ]);
  8. }

发表评论

表情:
评论列表 (有 0 条评论,353人围观)

还没有评论,来说两句吧...

相关阅读

    相关 登录验证

    验证码的作用是区分人与机器,防止机器刷数据; 验证码的验证分了两步,一步是请求获取验证码,一步是前台传的验证码与后台的验证码进行对比判断后进行后续操作; 在MyEclips