2014-11-24 88 views
-1

嗨我有登錄系統類似的應用程序在C#窗體中。當用戶輸入3次錯誤的詳細信息時,會發出一條消息並說ACCOUNT LOCKED。是否有任何技巧/方法凍結該用戶的帳戶幾秒鐘?帳戶凍結了幾秒

回答

0

有很多方法可以凍結一個帳戶。您可以設置權限列表。在權限列表中,您可以設置一個令牌並在每次有人嘗試登錄時增加它。如果令牌的值超過某個值,則用戶無法登錄某個時間幀,具體取決於DateTime設置。

你有什麼嘗試,如果有什麼?你有沒有可以分享的代碼,以便用戶能夠理解你想要進入的方向?

+0

我試過類似if(correct){proceed} else {wrongAttempt ++} if(wrongAttempts == 3){Console.WriteLine(「Account Lock」)}。 請向我解釋我可以用應用程序或用戶帳戶的30秒凍結時間替換帳戶鎖定的方式。 – saagar 2014-11-24 10:58:37

+1

FelipeKunzler對你來說是一個很好的開始。我會從那裏開始,並檢查是否需要更多幫助。 – 2014-11-24 12:31:47

1

當他被封鎖時,您可以創建一個字典,提供用戶名時間。例如: -

private Dictionary<string, DateTime> blockedUsers; 

登陸後,你會如果當前用戶在「blockedUsers」是否存在,如果真驗證,則必須比較當前時間和存儲在列表中的特定用戶的時間。如果它在30秒的範圍內,則可以取消顯示錯誤的登錄。否則,您將從阻止列表中刪除此用戶。事情是這樣的:

 // Checks if the user exists in the blockedUsers. 
     if (blockedUsers.ContainsKey(userName)) 
     { 
      // If so, then gets the difference between when he was blocked and now. 
      var diffInSeconds = (DateTime.Now - blockedUsers[userName]).TotalSeconds; 
      // If the difference is smaller than 30, prevent him from loggin. 
      if (diffInSeconds < 30) 
      { 
       MessageBox.Show("Sorry, but your user has been temporary blocked from loggin. Try later."); 
       return; 
      } 
      // If the diff is greater than 30, then there is no reason to keep him in blocked list. 
      else 
      { 
       blockedUsers.Remove(userName); 
      } 
     } 

你要做的另一件事是:如果「wrongAttempts」是3,那麼您將其添加在「blockedUsers」,如果他試圖在30秒再次登錄時,他會被第一次驗證所阻擋。

 if (wrongAttempts >= 3) 
     { 
      blockedUsers.Add(userName, DateTime.Now); 
     } 

就是這樣。希望它可以幫助你!

+0

謝謝大家的幫助。 – saagar 2014-11-24 12:39:58