3回

2017-02-18 1 views
0

evryoneあなたが..私は私がてtextBox名は持っているコミュニティ2015のVisual Studioを使用して、私のWindowsフォームアプリケーションのコードを持ってください私を助けることができるHI ユーザー名もう1つはパスワード、最後はログインログインするとツリータイムエラーが表示されますここで問題を自動的に忘れたパスワードとユーザーのパスワードを回復する方法を教えてください彼または彼女がフォームにログインするときにツリータイムエラーです。私のデータベースのフォームに行く前に私はあなたが助けて、どのように説明することができますか分かりません。ここ3回

は私のコードは、あなたがする必要がどのような

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

どのようなエラーコードが表示されますか? –

+0

@AidenGrossmanありがとうございます。私はエラーはありませんが、私の要点は、ユーザーがログインフォームのツリー時間にエラーが発生した場合、忘れたパスワードを表示したいということです。 – Sharkweb

答えて

0

でユーザー名とパスワードが有効でないときに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(); 
      } 
     } 
    } 
} 
+0

答えていただきありがとうございます。だからこそ、ユーザー名とパスワードの場合にはelseに属する条件を入れてください。 – Sharkweb

+0

私はもっと論理的になるように答えてコードを修正しました。最後の 'else'ブロックは、新しい変数' loginAttempts'の導入から離れて追加する必要があるブロックです。 –

+0

loginAttempts + = 1の用途は何ですか? – Sharkweb

関連する問題