2012-07-30 44 views
2

我的asp.net應用程序使用用戶登錄功能的自定義邏輯。其中一項要求是,用戶(一旦被鎖定)在15分鐘後才能獲得訪問權限。設置用戶登錄嘗試時的邏輯錯誤

我的當前的邏輯是:

// check if account is locked & LastLoginAttempt is NOT over 15 minutes; 
if ((iLoginAttempts > 4) && (dtCurrentTimePlus15 < dtLastLoginAttempt)) 
{ 
    oCust.CustLoginStatus = "Your account is currently locked."; 
    return false; 
} 

然而,當iLoginAttempts = 5和dtLastLoginAttempt是2分鐘前....爲何邏輯上述跳過如果條款?

+2

什麼是'dtCurrentTimePlus15'?無論如何,它應該是另一種方式:你應該添加15分鐘到'dtLastLoginAttempt',然後將它與當前時間進行比較。 – 2012-07-30 14:43:00

回答

1

這是因爲

dtCurrentTimePlus15 = 15 

dtLastLoginAttempt = 2 

倒轉聲明:

if ((iLoginAttempts > 4) && (dtLastLoginAttempt < dtCurrentTimePlus15)) 
{ 
    oCust.CustLoginStatus = "Your account is currently locked."; 
    return false; 
} 
+0

我知道它必須相當容易。謝謝@Leniel – DotNetRookie 2012-07-30 14:47:03

1

您應該使用邏輯or,而不是AND。只有滿足以下兩個條件時,您纔會鎖定某人:超過4次嘗試並且少於超時時間。

隨着or,你會鎖定任何人滿足這兩個條件中的一個或兩個。