英文:
Laravel Fortify 2FA Recovery Code Login Not Working
问题
我在我的应用程序中使用二次验证(2FA)的QR码功能,但恢复码路由出了一些问题。我总是收到以下错误消息:
提供的二次验证代码无效。
我不知道是我的表单使用的路由有问题,还是其他什么原因。这是我的表单:
<div class="col-md-12 ps-md-0" x-data="{ showRecovery: false, showCode: true }" x-cloak>
<div class="auth-form-wrapper px-4 py-5">
<form class="reset-password-form" method="POST" action="{{ route('two-factor.login') }}">
@csrf
<div x-show="showCode">
<h5 class="text-muted fw-normal mb-4 mt-4">输入验证代码</h5>
<div class="mb-3">
<input type="password" class="form-control" id="password" placeholder="代码" name="code">
@error('code')
<span class="invalid-feedback" style="display: block;" role="alert"><strong>{{ $message }}</strong></span>
@enderror
</div>
<div class="d-flex justify-content-start">
<button class="btn btn-primary me-2 mb-2 mb-md-0" type="submit">提交</button>
</div>
<a role="button" x-on:click="showRecovery = true, showCode = false" class="d-block mt-3 text-muted">使用恢复码</a>
</div>
<div x-show="showRecovery">
@csrf
<h5 class="text-muted fw-normal mb-4 mt-4">输入恢复码</h5>
<div class="mb-3">
<input type="text" class="form-control" id="recovery_code" placeholder="恢复码" name="recovery_code">
@error('recovery-code')
<span class="invalid-feedback" style="display: block;" role="alert"><strong>{{ $message }}</strong></span>
@enderror
</div>
<div class="d-flex justify-content-start">
<button class="btn btn-primary me-2 mb-2 mb-md-0" type="submit">提交</button>
</div>
<a role="button" x-on:click="showRecovery = false, showCode = true" class="d-block mt-3 text-muted">使用验证代码</a>
</div>
</form>
</div>
</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:
<div class="col-md-12 ps-md-0" x-data="{ showRecovery: false, showCode: true }" x-cloak>
<div class="auth-form-wrapper px-4 py-5">
<form class="reset-password-form" method="POST" action="{{ route('two-factor.login') }}">
@csrf
<div x-show="showCode">
<h5 class="text-muted fw-normal mb-4 mt-4">Enter Authentication Code</h5>
<div class="mb-3">
<input type="password" class="form-control" id="password" placeholder="Code" name="code">
@error('code')
<span class="invalid-feedback" style="display: block;" role="alert"><strong>{{ $message }} </strong></span>
@enderror
</div>
<div class="d-flex justify-content-start">
<button class="btn btn-primary me-2 mb-2 mb-md-0" type="submit">Submit</button>
</div>
<a role="button" x-on:click="showRecovery = true, showCode = false" class="d-block mt-3 text-muted">Use Recovery Code Instead</a>
</div>
<div x-show="showRecovery">
@csrf
<h5 class="text-muted fw-normal mb-4 mt-4">Enter Recovery Code</h5>
<div class="mb-3">
<input type="text" class="form-control" id="recovery_code " placeholder="Recovery Code" name="recovery_code ">
@error('recovery-code')
<span class="invalid-feedback" style="display: block;" role="alert"><strong>{{ $message }} </strong></span>
@enderror
</div>
<div class="d-flex justify-content-start">
<button class="btn btn-primary me-2 mb-2 mb-md-0" type="submit">Submit</button>
</div>
<a role="button" x-on:click="showRecovery = false, showCode = true" class="d-block mt-3 text-muted">Use Authentication Code Instead</a>
</div>
</form>
</div>
</div>
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属性中多了一个空格,可能会导致问题。请将此行更改为:
<input type="text" class="form-control" id="recovery_code" placeholder="Recovery Code" name="recovery_code">
英文:
@hyphen
In the recovery code input field, there's an extra space in the name attribute, which might cause issues. Change this line:
<input type="text" class="form-control" id="recovery_code " placeholder="Recovery Code" name="recovery_code ">
TO
<input type="text" class="form-control" id="recovery_code" placeholder="Recovery Code" name="recovery_code">
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论