简体   繁体   English

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

[英]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.

相关问题 如果用户多次输入无效的用户名和密码,如何终止程序 - how to Terminate program if user inputs invalid username and password several times MessageBox 出现三次后如何关闭表单? - How to close form after MessageBox shows up three times? 用户在文本框asp.net C#中输入一些值后,如何形成3位代码 - how to form a 3 digit code after a user enters some value in a textbox asp.net C# 用户进入后while不会结束 - While will not end after user enters 当用户输入凭据时,如何出现由凭据弹出窗口引起的异常,如何继续执行catch块? - How can I continue execution of a catch block when the user enters credentials, from an exception caused by a credentials popup appears? 密码恢复后重定向到登录页面 - Redirect to Login Page After Password Recovery 分割用户名和密码凭证 - Split user name and password credentials 连接到 HPC 调度程序时如何以编程方式设置用户密码凭据 - How to programatically set user password credentials when connecting to an HPC Scheduler 仅在用户提交表单后如何显示EmptyDataText? - How do I show EmptyDataText only after the user submits the form? 如何始终在逗号后显示三位数字 - How to always show three digits after the comma
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM