static void Main() { SQLCode sql = new SQLCode(); // Check for valid connection if (sql.isServerConnected() == false) { MessageBox.Show("No connection to database.\nServer IP Address may need to be updated\nor the internet is out\nor the power is out", "Elode", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } // Check for latest version else if (sql.checkVersion() != 14) { if (MessageBox.Show("Your client is not the latest version. Click \"OK\" to update to the latest version of the software.", "Elode", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { System.Diagnostics.Process.Start("https://v1perw0lf.github.io/Elode/"); } Application.Exit(); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainWindow()); } }
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); } }
private void registerButton_Click(object sender, EventArgs e) { errorLabel.Text = "Registering..."; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox2.Location.Y + passwordBox2.Height + 13); if (usernameBox.Text.Length < 4 || usernameBox.Text.Length > 24) { errorLabel.Text = "Username must be between 4 and 24 characters long"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox2.Location.Y + passwordBox2.Height + 13); } else if (passwordBox1.Text != passwordBox2.Text) { errorLabel.Text = "Passwords do not match!"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox2.Location.Y + passwordBox2.Height + 13); } else if (passwordBox1.Text.Length < 6 || passwordBox1.Text.Length > 16) { errorLabel.Text = "Password must be between 6 and 16 characters long"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox2.Location.Y + passwordBox2.Height + 13); } else if (sql.isServerConnected() == false) { errorLabel.Text = "No connection to database"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox2.Location.Y + passwordBox2.Height + 13); } else { // Passwords match, so encrypt chosen password and add user to database try { string encryptedPass = StringCipher.Encrypt(passwordBox1.Text, key); sql.addUser(usernameBox.Text, encryptedPass); errorLabel.Text = "Successfully registered"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox2.Location.Y + passwordBox2.Height + 13); backButton.Focus(); } // If username exists already, tell user catch (MySqlException ex) { if (ex.Number == 1062) { errorLabel.Text = "Username already taken"; errorLabel.Location = new Point((ActiveForm.Width - errorLabel.Width) / 2, passwordBox2.Location.Y + passwordBox2.Height + 13); } } } }