Laravel Fortify 2FA恢复码登录不起作用

huangapple go评论109阅读模式
英文:

Laravel Fortify 2FA Recovery Code Login Not Working

问题

我在我的应用程序中使用二次验证(2FA)的QR码功能,但恢复码路由出了一些问题。我总是收到以下错误消息:

提供的二次验证代码无效。

我不知道是我的表单使用的路由有问题,还是其他什么原因。这是我的表单:

  1. <div class="col-md-12 ps-md-0" x-data="{ showRecovery: false, showCode: true }" x-cloak>
  2. <div class="auth-form-wrapper px-4 py-5">
  3. <form class="reset-password-form" method="POST" action="{{ route('two-factor.login') }}">
  4. @csrf
  5. <div x-show="showCode">
  6. <h5 class="text-muted fw-normal mb-4 mt-4">输入验证代码</h5>
  7. <div class="mb-3">
  8. <input type="password" class="form-control" id="password" placeholder="代码" name="code">
  9. @error('code')
  10. <span class="invalid-feedback" style="display: block;" role="alert"><strong>{{ $message }}</strong></span>
  11. @enderror
  12. </div>
  13. <div class="d-flex justify-content-start">
  14. <button class="btn btn-primary me-2 mb-2 mb-md-0" type="submit">提交</button>
  15. </div>
  16. <a role="button" x-on:click="showRecovery = true, showCode = false" class="d-block mt-3 text-muted">使用恢复码</a>
  17. </div>
  18. <div x-show="showRecovery">
  19. @csrf
  20. <h5 class="text-muted fw-normal mb-4 mt-4">输入恢复码</h5>
  21. <div class="mb-3">
  22. <input type="text" class="form-control" id="recovery_code" placeholder="恢复码" name="recovery_code">
  23. @error('recovery-code')
  24. <span class="invalid-feedback" style="display: block;" role="alert"><strong>{{ $message }}</strong></span>
  25. @enderror
  26. </div>
  27. <div class="d-flex justify-content-start">
  28. <button class="btn btn-primary me-2 mb-2 mb-md-0" type="submit">提交</button>
  29. </div>
  30. <a role="button" x-on:click="showRecovery = false, showCode = true" class="d-block mt-3 text-muted">使用验证代码</a>
  31. </div>
  32. </form>
  33. </div>
  34. </div>

当我运行 php artisan route:list 时,我看不到名为 two-factor.login 的路由,但使用验证代码时它能够正常工作。我假设使用恢复码时应该使用相同的路由。

我还尝试过将表单操作设置为 /two-factor-challenge,但结果相同。

英文:

I've got 2FA working in my app with the qr code, but the recovery code route isn't working for some reason. I always get the error:

The provided two factor authentication code was invalid.

I don't know if it's the route I'm using in my form, or what. Here's the form:

  1. &lt;div class=&quot;col-md-12 ps-md-0&quot; x-data=&quot;{ showRecovery: false, showCode: true }&quot; x-cloak&gt;
  2. &lt;div class=&quot;auth-form-wrapper px-4 py-5&quot;&gt;
  3. &lt;form class=&quot;reset-password-form&quot; method=&quot;POST&quot; action=&quot;{{ route(&#39;two-factor.login&#39;) }}&quot;&gt;
  4. @csrf
  5. &lt;div x-show=&quot;showCode&quot;&gt;
  6. &lt;h5 class=&quot;text-muted fw-normal mb-4 mt-4&quot;&gt;Enter Authentication Code&lt;/h5&gt;
  7. &lt;div class=&quot;mb-3&quot;&gt;
  8. &lt;input type=&quot;password&quot; class=&quot;form-control&quot; id=&quot;password&quot; placeholder=&quot;Code&quot; name=&quot;code&quot;&gt;
  9. @error(&#39;code&#39;)
  10. &lt;span class=&quot;invalid-feedback&quot; style=&quot;display: block;&quot; role=&quot;alert&quot;&gt;&lt;strong&gt;{{ $message }} &lt;/strong&gt;&lt;/span&gt;
  11. @enderror
  12. &lt;/div&gt;
  13. &lt;div class=&quot;d-flex justify-content-start&quot;&gt;
  14. &lt;button class=&quot;btn btn-primary me-2 mb-2 mb-md-0&quot; type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
  15. &lt;/div&gt;
  16. &lt;a role=&quot;button&quot; x-on:click=&quot;showRecovery = true, showCode = false&quot; class=&quot;d-block mt-3 text-muted&quot;&gt;Use Recovery Code Instead&lt;/a&gt;
  17. &lt;/div&gt;
  18. &lt;div x-show=&quot;showRecovery&quot;&gt;
  19. @csrf
  20. &lt;h5 class=&quot;text-muted fw-normal mb-4 mt-4&quot;&gt;Enter Recovery Code&lt;/h5&gt;
  21. &lt;div class=&quot;mb-3&quot;&gt;
  22. &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;recovery_code &quot; placeholder=&quot;Recovery Code&quot; name=&quot;recovery_code &quot;&gt;
  23. @error(&#39;recovery-code&#39;)
  24. &lt;span class=&quot;invalid-feedback&quot; style=&quot;display: block;&quot; role=&quot;alert&quot;&gt;&lt;strong&gt;{{ $message }} &lt;/strong&gt;&lt;/span&gt;
  25. @enderror
  26. &lt;/div&gt;
  27. &lt;div class=&quot;d-flex justify-content-start&quot;&gt;
  28. &lt;button class=&quot;btn btn-primary me-2 mb-2 mb-md-0&quot; type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
  29. &lt;/div&gt;
  30. &lt;a role=&quot;button&quot; x-on:click=&quot;showRecovery = false, showCode = true&quot; class=&quot;d-block mt-3 text-muted&quot;&gt;Use Authentication Code Instead&lt;/a&gt;
  31. &lt;/div&gt;
  32. &lt;/form&gt;
  33. &lt;/div&gt;
  34. &lt;/div&gt;

When I do php artisan route:list I don't see a route for two-factor.login, but it works with the authentication code. I'm assuming it should be the same route for using the recovery code as well.

I've also tried using /two-factor-challenge as the form action but I get the same result.

答案1

得分: 0

在恢复代码输入字段中,name属性中多了一个空格,可能会导致问题。请将此行更改为:

  1. &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;recovery_code&quot; placeholder=&quot;Recovery Code&quot; name=&quot;recovery_code&quot;&gt;
英文:

@hyphen

In the recovery code input field, there's an extra space in the name attribute, which might cause issues. Change this line:

  1. &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;recovery_code &quot; placeholder=&quot;Recovery Code&quot; name=&quot;recovery_code &quot;&gt;

TO

  1. &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;recovery_code&quot; placeholder=&quot;Recovery Code&quot; name=&quot;recovery_code&quot;&gt;

huangapple
  • 本文由 发表于 2023年7月27日 20:27:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76779738.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定