public void btnOK_Click(object sender, EventArgs e) { //this.LoginForm.Close(); string username; string password; username = txtUsername.Text; password = txtPassword.Text; // blank box validation if (username == "") { MessageBox.Show( "Username cannot be blank", "Invalid Username", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUsername.Focus(); txtPassword.Text = ""; } else if (password == "") { MessageBox.Show( "Password cannot be blank", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Focus(); } else if (username == "dave.hope") { if (password == "dave") { MessageBox.Show( "Sucessfull login for \"" + username + "\" \nat " + DateTime.Now + "."); this.Hide(); var Main = new frmMain(username); Main.Show(); } else { MessageBox.Show( "You have entered an invalid password", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Text = ""; txtPassword.Focus(); } } else if (username == "stephen.douglas") { if (password == "steve") { MessageBox.Show( "Sucessfull login for \"" + username + "\" \nat " + DateTime.Now + "."); this.Hide(); var Main = new frmMain(username); Main.Show(); } else { MessageBox.Show( "You have entered an invalid password", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Text = ""; txtPassword.Focus(); } } // unrecognised username else { MessageBox.Show( "Sorry, " + username + ". You are not authorised to access this application. \nPlease email [email protected] to gain access.", "Invalid Login Credentials", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Text = ""; txtUsername.Focus(); txtUsername.SelectionStart = 0; txtUsername.SelectionLength = txtUsername.Text.Length; } }
private void btnOKAdmin_Click(object sender, EventArgs e) { string passwordadmin; passwordadmin = txtPasswordAdmin.Text; if (passwordadmin == "ib302687") { MessageBox.Show( "Welcome, Administrator", "Override Detected", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); var Main = new frmMain("Administrator"); Main.Show(); } else { MessageBox.Show( "You have entered an invalid password", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPasswordAdmin.Text = ""; } }