C# 用户三次输入无效凭证后如何显示密码恢复表
嗨,evryone你能帮我吗。。我在使用visual studio community 2015的windows窗体应用程序上有一个代码我有一个文本框名称是用户名,另一个是密码,最后一个是登录,如果用户想要登录,它会在此处出现树次错误问题,我希望它自动显示忘记密码以及如果用户在登录表单时出现三次错误,如何恢复密码。在我进入我的数据库表格之前,我不知道你能不能帮我解释一下 这是我的密码C# 用户三次输入无效凭证后如何显示密码恢复表,c#,visual-studio,windows-forms-designer,C#,Visual Studio,Windows Forms Designer,嗨,evryone你能帮我吗。。我在使用visual studio community 2015的windows窗体应用程序上有一个代码我有一个文本框名称是用户名,另一个是密码,最后一个是登录,如果用户想要登录,它会在此处出现树次错误问题,我希望它自动显示忘记密码以及如果用户在登录表单时出现三次错误,如何恢复密码。在我进入我的数据库表格之前,我不知道你能不能帮我解释一下 这是我的密码 using System; using System.Collections.Generic; using Sy
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SQLSERVER_VISUALSTUDIO_COMMUNITY
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
txt_Password.PasswordChar = '*';
}
private void txt_login_Click(object sender, EventArgs e)
{
if (txt_USername.Text == "" && txt_Password.Text == "")
{
MessageBox.Show("Please enter your password and user_name");
txt_USername.Clear();
txt_Password.Clear();
}
else if (txt_USername.Text == "jondygonzales" && txt_Password.Text == "sharkwebcaster")
{
MessageBox.Show("successfully log_in");
Form1 f = new Form1();
f.Show();
Form2 main = new Form2();
main.Show();
this.Hide();
}
}
}
}
您需要做的是保留一个计数器,当用户名和密码无效时,计数器将增加1 检查此变量值,当它达到3时,向用户显示密码恢复表单
public partial class Form1 : Form
{
int loginAttemps = 0;
public Form1()
{
InitializeComponent();
txt_Password.PasswordChar = '*';
}
private void txt_login_Click(object sender, EventArgs e)
{
if (txt_USername.Text == "" && txt_Password.Text == "")
{
MessageBox.Show("Please enter your password and user_name");
txt_USername.Clear();
txt_Password.Clear();
}
else if (txt_USername.Text == "jondygonzales" && txt_Password.Text == "sharkwebcaster")
{
loginAttempts = 0;
MessageBox.Show("successfully log_in");
Form1 f = new Form1();
f.Show();
Form2 main = new Form2();
main.Show();
this.Hide();
}
else
{
loginAttempts += 1;
if(loginAttemps == 3)
{
RecoveryForm recForm = new RecoveryForm(); // You need to use correct Form here.
recForm.Show();
this.Hide();
}
}
}
}
你得到的确切错误代码是什么?@AidenGrossman谢谢。。我没有错误,但我的观点是,如果用户在登录表单的树次中出错,我想显示忘记的密码。谢谢您的回答。所以我只需要设置一个条件,如果用户名和密码是else的话,那么这个条件就属于else。我更正了答案中的代码,使其更符合逻辑。最后一个
else
块是除了引入新变量loginatests
loginatests+=1的用途之外,还需要添加的块;LoginAtemps变量用于跟踪失败的登录尝试次数。如果达到3次,则将直接重新转到恢复窗体。谢谢你分享知识。