private void loginButton_Click(object sender, EventArgs e) { errorLabel.Text = "Logging in..."; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox.Location.Y + passwordBox.Height + 13); if (usernameBox.TextLength > 0 && passwordBox.TextLength > 0) { if (sql.isServerConnected()) { if (sql.findPass(usernameBox.Text) != "") { try { // Searches for username entered and then decrypts password from database file string decryptedPassword = StringCipher.Decrypt(sql.findPass(usernameBox.Text), key); // Checks decrypted password against password entered if (decryptedPassword == passwordBox.Text) { username = usernameBox.Text; MainWindow main = new MainWindow(); main.username = username; Hide(); main.Show(); } else { errorLabel.Text = "Wrong username or password!"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox.Location.Y + passwordBox.Height + 13); } } catch (MySqlException ex) { errorLabel.Text = ex.Message; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox.Location.Y + passwordBox.Height + 13); } } else { errorLabel.Text = "Wrong username or password!"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox.Location.Y + passwordBox.Height + 13); } } else { errorLabel.Text = "No connection to database"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox.Location.Y + passwordBox.Height + 13); } } else { errorLabel.Text = "Username or password field empty"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox.Location.Y + passwordBox.Height + 13); } }