消息框出现问题 [英] got problem with messagebox

查看:112
本文介绍了消息框出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我创建了一个程序,如果用户输入错误的密码,则该用户登录,它将提示一条消息,最多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?

推荐答案

您可以使用 ^ ],其中键是用户名,值是该用户的尝试次数.
You could use a Dictionary<TKey, TValue>[^] where the key is the username and the value is the attempts that are left for this user.
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! :)


这篇关于消息框出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆