private void btnLogin_Click(object sender, EventArgs e) { string thefile = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + Path.DirectorySeparatorChar + "users.txt"; fileExists = File.Exists(thefile); using (TextReader tr = File.OpenText(thefile)) { string strLine = string.Empty; string[] arrColumn = null; string[,] arrColumns = new string[3, 3]; bool booLogin = false; int randomInt = 0; while ((strLine = tr.ReadLine()) != null) { arrColumn = strLine.Split(','); for (int x = 0; x <= 2; x++) { arrColumns[randomInt, x] = arrColumn[x]; } randomInt++; } int lengthA = arrColumns.Length; for (int x = 0; x <= 2; x++) { if (usrName.Text == arrColumns[x, 0] && usrPswd.Text == arrColumns[x, 1]) { booLogin = true; if (MessageBox.Show("Continue", "Cancel", MessageBoxButtons.YesNo) == DialogResult.Yes) { ConfirmPosition form = new ConfirmPosition(); form.ShowDialog(); } else { MessageBox.Show("You pressed cancel, you failed"); } } } if (booLogin == false) { MessageBox.Show("User name or Password Was Wrong"); } } }
private void btnLogin_Click(object sender, EventArgs e) { string thefile = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + Path.DirectorySeparatorChar + "users.txt"; fileExists = File.Exists(thefile); using (TextReader tr = File.OpenText(thefile)) { string strLine = string.Empty; string[] arrColumn = null; string[,] arrColumns = new string[3,3]; bool booLogin = false; int randomInt = 0; while ((strLine = tr.ReadLine()) != null) { arrColumn = strLine.Split(','); for (int x = 0; x <= 2; x++) { arrColumns[randomInt, x] = arrColumn[x]; } randomInt++; } int lengthA = arrColumns.Length; for (int x = 0; x <= 2; x++) { if (usrName.Text == arrColumns[x,0] && usrPswd.Text == arrColumns[x,1]) { booLogin = true; if (MessageBox.Show("Continue", "Cancel", MessageBoxButtons.YesNo) == DialogResult.Yes) { ConfirmPosition form = new ConfirmPosition(); form.ShowDialog(); } else { MessageBox.Show("You pressed cancel, you failed"); } } } if (booLogin == false) { MessageBox.Show("User name or Password Was Wrong"); } } }