PasswordSignInAsync() 和 MaxFailedAccessAttempts 究竟是如何连接的?
How exactly PasswordSignInAsync() and MaxFailedAccessAttempts connect?
因此,方法 SignInManager.PasswordSignInAsync
has a last parameter lockoutOnFailure
which when true, locks out the user if they enter wrong credentials. But there is already a property called MaxFailedAccessAttempts
在(默认情况下)5 次成功事件后锁定用户。
我在这里有些困惑,无法根据第 4 个参数找到此方法如何工作的答案。如果已经设置了何时锁定的选项,为什么我们需要设置 lockoutOnFailure?我不想将其设置为 true。
我的理解是:
如果 lockoutOnFailure: true
,那么即使这是用户第一次尝试登录,如果他们输入错误的凭据,他们也会被锁定。如果 lockoutOnFailure: false
,那么即使是第 5 次尝试输入错误的凭据,也不会被锁定。我不想这两种情况都发生,所以我不想将它设置为任何一个值。我应该怎么办?还是我理解错了方法?
ASP.NET Core Identity 是开源的,意味着您可以轻松查看代码。 PasswordSignInAsync 最终调用 CheckPasswordSignInAsync 方法。
哪个
if (UserManager.SupportsUserLockout && lockoutOnFailure)
{
// If lockout is requested, increment access failed count which might lock out the user
await UserManager.AccessFailedAsync(user);
if (await UserManager.IsLockedOutAsync(user))
{
return await LockedOut(user);
}
}
这意味着,MaxFailedAccessAttempts
可能是全局设置的,但除非使用 lockoutOnFailure
调用登录方法,否则不会检查它。
文档已经注意到这一点,但措辞有点奇怪:
Gets or sets the number of failed access attempts allowed before a user is locked out, assuming lock out is enabled. Defaults to 5.
lockoutOnFailure
参数是启用机制。 PasswordSignInAsync
的文档说明了这一点。
Flag indicating if the user account should be locked if the sign in fails.
如果标志设置为 false
,则失败的尝试 不会增加 失败的登录计数器。
但是,一旦帐户被锁定,PasswordSignInAsync
将返回 LockedOut
结果,即使 lockedOnFailure
设置为 false。此参数仅确定计数器是否会在失败时增加(并且一旦超过将帐户标记为锁定)。
因此,方法 SignInManager.PasswordSignInAsync
has a last parameter lockoutOnFailure
which when true, locks out the user if they enter wrong credentials. But there is already a property called MaxFailedAccessAttempts
在(默认情况下)5 次成功事件后锁定用户。
我在这里有些困惑,无法根据第 4 个参数找到此方法如何工作的答案。如果已经设置了何时锁定的选项,为什么我们需要设置 lockoutOnFailure?我不想将其设置为 true。
我的理解是:
如果 lockoutOnFailure: true
,那么即使这是用户第一次尝试登录,如果他们输入错误的凭据,他们也会被锁定。如果 lockoutOnFailure: false
,那么即使是第 5 次尝试输入错误的凭据,也不会被锁定。我不想这两种情况都发生,所以我不想将它设置为任何一个值。我应该怎么办?还是我理解错了方法?
ASP.NET Core Identity 是开源的,意味着您可以轻松查看代码。 PasswordSignInAsync 最终调用 CheckPasswordSignInAsync 方法。
哪个
if (UserManager.SupportsUserLockout && lockoutOnFailure)
{
// If lockout is requested, increment access failed count which might lock out the user
await UserManager.AccessFailedAsync(user);
if (await UserManager.IsLockedOutAsync(user))
{
return await LockedOut(user);
}
}
这意味着,MaxFailedAccessAttempts
可能是全局设置的,但除非使用 lockoutOnFailure
调用登录方法,否则不会检查它。
文档已经注意到这一点,但措辞有点奇怪:
Gets or sets the number of failed access attempts allowed before a user is locked out, assuming lock out is enabled. Defaults to 5.
lockoutOnFailure
参数是启用机制。 PasswordSignInAsync
的文档说明了这一点。
Flag indicating if the user account should be locked if the sign in fails.
如果标志设置为 false
,则失败的尝试 不会增加 失败的登录计数器。
但是,一旦帐户被锁定,PasswordSignInAsync
将返回 LockedOut
结果,即使 lockedOnFailure
设置为 false。此参数仅确定计数器是否会在失败时增加(并且一旦超过将帐户标记为锁定)。