[英]How to show password recovery form after user enters invalid credentials three times
hi evryone can you help me please.. i have a code on my windows form application using visual studio community 2015 I have a textBox the name is username the other one is password and the last is login if the user want to login and it will get a tree times error here the problem I want it automatically show the forgot password and how to recover password if the user is tree times error when he or she login the form. 嗨,evryone可以帮我吗..我在使用Visual Studio Community 2015的 Windows窗体应用程序上有一个代码,我有一个textBox ,名称是用户名 ,另一个是密码 ,最后一个是登录,如果用户要登录,它将在这里得到一个tree times错误,我想要它自动显示忘记密码的问题,以及如果用户在登录表单时是tree times错误,该如何恢复密码。 before I'll go to my database form i have no idea can you help please and explain how.
在我进入数据库表格之前,我不知道您能不能帮助您并解释如何做。
here is my code 这是我的代码
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();
}
}
}
}
What you need to do is keep a counter which you will increase by one when username and password are not valid. 您需要做的是保持一个计数器,当用户名和密码无效时,计数器将增加一。
You check this variable value and when it reaches 3, you show user the password recovery form. 您检查此变量值,当它达到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();
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.