簡體   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