2011-12-28 36 views
1

我嘗試做三次不使用數據庫嘗試失敗後鎖定用戶的研究,並且我找到了與SQLMemberShipProvider一起使用它的答案。我修改th Web.config:用maxInvalidPasswordAttempts鎖定用戶不起作用

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/LogOnCust" timeout="2880" /> 
</authentication> 
<membership> 
    <providers> 
    <clear /> 
    <add name="AspNetSqlMembershipProvider" 
    type="System.Web.Security.SqlMembershipProvider" 
    connectionStringName="WebDBConnection" 
    maxInvalidPasswordAttempts="3" 
    minRequiredPasswordLength="6" 
    passwordAttemptWindow="10" 
    applicationName="/" /> 
    </providers> 
</membership> 

但它不工作,我不知道爲什麼。我需要做些什麼修改才能使更多?

+0

maxInvalidPasswordAttempts =「5」!= 3 http://msdn.microsoft.com/en-us/library/system.web.security.membership.maxinvalidpasswordattempts.aspx – xQbert 2011-12-28 02:02:11

+0

那麼你是說你沒有使用數據庫?或者你是和看不到字段增量作爲無效的密碼嘗試發生? – uadrive 2011-12-28 02:06:56

+0

@uadrive:我試過了,用我自己的帳戶用不正確的密碼登錄了3次,但我仍然可以在第4次登錄網頁。所以我不知道我能做什麼或看到有關錯誤。 – Nothing 2011-12-28 02:16:09

回答

2

嘗試設置您的默認成員資格提供程序,看看是否有幫助。

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/LogOnCust" timeout="2880" /> 
</authentication> 
<membership defaultProvider="AspNetSqlMembershipProvider"> 
    <providers> 
    <clear /> 
    <add name="AspNetSqlMembershipProvider" 
    type="System.Web.Security.SqlMembershipProvider" 
    connectionStringName="WebDBConnection" 
    maxInvalidPasswordAttempts="3" 
    minRequiredPasswordLength="6" 
    passwordAttemptWindow="10" 
    applicationName="/" /> 
    </providers> 
</membership> 

此外,檢查,以確保存儲過程是否正確安裝,我知道我遇到了與Oracle這個問題,但使用SQL Server時,並沒有太多的問題。不傷害檢查。

+0

我添加了這個: 但是它仍然沒有什麼效果,而我登錄失敗3次:( – Nothing 2011-12-28 02:50:04

+1

你可以發佈你的登錄代碼?我想知道如果問題存在的地方。你使用帳戶登錄MVC生成的代碼與單元測試?如果是,請給我顯示ValidateUser(字符串用戶名,字符串密碼)方法。 – uadrive 2011-12-29 21:48:21

+0

我有一些混淆,現在它完美。謝謝。 – Nothing 2011-12-30 05:44:46

0

我有同樣的問題。我的原因是用戶未被批准。用戶獲得批准後,每次失敗嘗試後,「FailedPasswordAttemptCount」都會遞增。