问题描述
嘿,我创建了一个程序,如果用户输入错误的密码,则该用户登录,它将提示一条消息,最多3次尝试.
例如剩余1-2次尝试,剩余2-1次尝试,3次-您没有剩余尝试且密码被阻止了
这里的代码
hey i have created a program which the user login if the user enter wrong password it will prompt a message up to 3 attempts
such as 1 - 2 attempts left, 2 - 1 attempt left, 3 - you have no attempt left and your password been blocked
here the code
int attempt = 3;
if (!pin.Equals("...") && attempts > 1)
{
attempts--;
MessageBox.Show("Wrong pin number! " + attempts + " attempts left");
}
else if (!pin.Equals("...")&& attempts==1)
{
MessageBox.Show("wrong password! your account been blocked");
}
我遇到的问题是将其分配给每个用户名,我希望每个单独的用户名在阻止其密码之前都要进行3次尝试.
problem i got is it assign it to every username where i want each indivdual username to have 3 attempts each before their password is blocked.
how would i do this?
推荐答案
Dictionary<String, int> usersAndAttempts = new Dictionary<String, int>();
if (!usersAndAttempts.ContainsKey(userName))
{
// Add the user and his three attempts to the dictionary.
}
// Your code here, but gettings the attempts from the dictionary where the key is the specified user.
当然,这将给每个用户三个登录名,直到他重新启动您的应用程序,此后,他的三个尝试将被重置.要永久阻止该用户,您必须向数据库中写入一些内容,以表明指定的用户已被锁定.
希望能帮助到你! :)
Of course this will give every user three logins until he restarts your application, after which his three attempts will be reset. To permanently block the user you''d have to write something to a database which indicates that the specified user is locked.
Hope it helps! :)
这篇关于消息框出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!