private void button1_Click(object sender, EventArgs e) { passwordAttempts += 1; string username = Properties.Settings.Default.app_connectedUsername; string password = textBox1.Text; if (textBox1.Text == "") { passwordLabel.Text = "Please enter your password!"; } try { SqlCeConnection DMDatabase = new SqlCeConnection(); DMDatabase.ConnectionString = Properties.Settings.Default.DMConnectionString; DMDatabase.Open(); SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM employees WHERE username='******'", DMDatabase); SqlCeDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { if (this.CompareStrings(dr["username"].ToString(), username) && this.CompareStrings(dr["password"].ToString(), password)) { passwordCorrect = true; this.Close(); } else { DMParent frm = new DMParent(); frm.applicationStatusChange("Password Incorrect! This is attempt " + passwordAttempts + " of " + maxPasswordAttempts + "."); passwordLabel.Text = "Password Incorrect! This is attempt " + passwordAttempts + " of " + maxPasswordAttempts + "."; if (passwordAttempts == maxPasswordAttempts) { passwordCorrect = false; this.Close(); } else { /* Password was simply incorrect * No need to increase password attempt * That is done when the button is first clicked */ } } } dr.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void ExitLockMode(Form myFrm, string pMsg) { try { DMParent parent = (DMParent)myFrm.MdiParent; parent.returnFromLock("Application Ready", true); } catch (Exception ex) { MessageBox.Show("An error occured!" + ex); } }
private void radButton1_Click(object sender, EventArgs e) { passwordAttempts += 1; passwordLabel.Text = ""; string username = usernameBox.Text; string password = passwordBox.Text; int empID; if (usernameBox.Text == "" || passwordBox.Text == "") { passwordLabel.Text = "Please enter your username or password!"; } try { SqlCeConnection DMDatabase = new SqlCeConnection(); DMDatabase.ConnectionString = Properties.Settings.Default.DMConnectionString; DMDatabase.Open(); SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM employees WHERE username='******'", DMDatabase); SqlCeDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { //TODO: if statement to see if username is in database, if not, +1 to passwordattempts //passwordLabel.Text = "User not found! This is attempt " + passwordAttempts + " of " + maxPasswordAttempts + "."; if (this.CompareStrings(dr["username"].ToString(), username) && this.CompareStrings(dr["password"].ToString(), password)) { //AUTENTICATION IS SUCESSFUL string fullname = dr["firstname"] + " " + dr["lastname"]; object o = dr["empID"]; empID = (int)o; /* This captures the users information that is required for features of the application * All required info is captured here rather than someone else * When a user logs out of the application, the DMParent is closed and Login Form is shown * This ensures that all of the data is captured since all of the code is in one place */ Properties.Settings.Default.app_connectedUser = fullname; Properties.Settings.Default.app_connectedUsername = username; Properties.Settings.Default.app_connectedUserID = empID; /* Must hide login form instead of closing it * If it is closed, the application will exit. * Handle the exiting of the application via the closing of DMParent */ this.Hide(); //Open DMParent DMParent frm = new DMParent(); frm.Show(); } else { //AUTENTICATION FAILED passwordLabel.Text = "Password Incorrect! This is attempt " + passwordAttempts + " of " + maxPasswordAttempts + "."; if (passwordAttempts == maxPasswordAttempts) { Application.Exit(); } else { /* Password was simply incorrect * No need to increase password attempt * That is done when the button is first clicked */ } } } dr.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }