繁体   English   中英

用户输入无效凭据三次后如何显示密码恢复表单

[英]How to show password recovery form after user enters invalid credentials three times

嗨,evryone可以帮我吗..我在使用Visual Studio Community 2015的 Windows窗体应用程序上有一个代码,我有一个textBox ,名称是用户名 ,另一个是密码 ,最后一个是登录,如果用户要登录,它将在这里得到一个tree times错误,我想要它自动显示忘记密码的问题,以及如果用户在登录表单时是tree times错误,该如何恢复密码。 在我进入数据库表格之前,我不知道您能不能帮助您并解释如何做。

这是我的代码

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(); 
            }
        }
    }
}

您需要做的是保持一个计数器,当用户名和密码无效时,计数器将增加一。

您检查此变量值,当它达到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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM