World of Warcraft login System
FrmLogin
FrmRegister
FrmMain
2. Let's take a look at the code of the first form.
First, double-click the form to go to the code page.
Public UserInfo [] users = new UserInfo [10]; // create an array with a length of 0 private void FrmLogin_Load (object sender, EventArgs e) // double-click the FORM {// 01. assign InitDataToArray ();} private void InitDataToArray () to the first three positions of the array // Method for assigning an initial value to the array {UserInfo user1 = new UserInfo (); // assign the value to user1.Uid = 1; user1.Uemail = "1"; user1.Upwd = "1"; // assign the free user1 object to users array users [0] = user1; users [1] = new UserInfo (); // second method of value assignment users [1]. uid = 2; users [1]. uemail = "2"; users [1]. upwd = "2 ";}
Double-click the login button
Private void btnLogin_Click (object sender, EventArgs e) // double-click the logon button {// 1.0, indicating that the logon result is bool flag = false; // 1.1 determine whether the email address and password entered by the user are correct string email = txtEmail. text; string pwd = txtPwd. text; // 1.2 traverse the array cyclically, and retrieve each item in turn (UserInfo item in users) {// 1.3 each item represents a UserInfo object if (item! = Null) {if (item. uemail. equals (email) & item. upwd. equals (pwd) {// verify that both the email address and password match the flag = true ;}}// 1.4 except for loops, determine whether flag is true or false if (flag = true) {// enter the main form FrmMain frm = new FrmMain (); frm. email = txtEmail. text; frm. show ();} else {MessageBox. show ("Logon Failed ");}
We want to register an account for a user without an account.
Private void llbRegist_LinkClicked (object sender, LinkLabelLinkClickedEventArgs e) // double-click the register button {// 01. hide by yourself // this indicates the current form object this. hide (); // 02. display FrmRegister frm = new FrmRegister (); frm. login = this; frm. show ();}
Registration on the second page
// Define the value of the form object stored in the logininfo form. public FrmLogin fl; // click private void btnregin_Click (object sender, EventArgs e) of the event triggered by registration) // double-click Register war network {if (ProvingInfo () = true) {// obtain the value string name = txtname in the text box. text; string email = txtemail. text; string cid = txtcid. text; string password = txtpassword. text; LoginInfo info = new LoginInfo (); info. name = name; info. id = cid; info. email = email; info. password = password; Mess AgeBox. Show ("registration successful! "); For (int I = 0; I <LoginInfo. array. length; I ++) {if (LoginInfo. array [I] = null) {LoginInfo. array [I] = info; break ;}}// enter the public bool ProvingInfo () {if (txtname. text. trim (). equals (string. empty) {MessageBox. show ("Please enter name"); this.txt name. focus (); return false;} else if (txtcid. text. trim (). equals (string. empty) {MessageBox. show ("Enter your ID number"); this.txt cid. focus (); return false;} else if (Txtemail. text. trim (). equals (string. empty) {MessageBox. show ("Enter your ID number"); this.txt email. focus (); return false;} else if (txtpassword. text. trim (). equals (string. empty) {MessageBox. show ("Enter password"); this.txt password. focus (); return false;} else if (txtone. text. trim (). equals (string. empty) {MessageBox. show ("Please confirm email input"); this.txt one. focus (); return false;} else if (txtokone. text. trim (). equals (string. em Pty) {MessageBox. Show ("Confirm Password Input"); this.txt okone. Focus (); return false;} else if (! Txtemail. Text. Equals (txtone. Text) {MessageBox. Show ("two input mailboxes are inconsistent"); return false;} else if (! Txtpassword. Text. Equals (txtokone. Text) {MessageBox. Show ("two passwords are inconsistent"); return false ;}else {return true ;}
The third page displays "Welcome ***".
// Define the variable to save the value passed in the form public string loginame; // Load event private void FrmMain_Load (object sender, EventArgs e) // double-click the FORM {// assign lblloginname to the label control. text = "welcome" + loginame + "to World of Warcraft ";}