private void Register_Click(object sender, RoutedEventArgs e) { password = Password_tf.Password; if ((Boolean)YesNew.IsChecked) { new_user = true; } User user = new User(name, surname, username, password, new_user); bool exist = false; string message = "Username already exist!! Try again"; if (Username_tf.Text != "") { foreach (User u in Lists.User_list) { if (u.Username.Equals(username)) { exist = true; } } } else { exist = true; message = "Username is missing, please fill text field!"; } if (!exist) { if (password.Length < 8) { MessageBox.Show("Passowrd must contain at least 8 characters!! Try again!"); Password_tf.Clear(); Re_Password_tf.Clear(); } else { if (Password_tf.Password == Re_Password_tf.Password) { Lists.User_list.Add(user); this.Close(); } else { MessageBox.Show("Please re-enter same password!!"); Re_Password_tf.Clear(); } } } else { MessageBox.Show(message); Username_tf.Clear(); } }
private void Login_Click(object sender, RoutedEventArgs e) { Boolean exists = false; Boolean wrong_password = true; foreach (User user in Lists.User_list) { if (user.Username.Equals(Login_tf.Text)) { exists = true; if (user.Password.Equals(Password_tf.Password)) { wrong_password = false; } } } if (exists) { if (!wrong_password) { MainWindow main = new MainWindow(); main.Show(); this.Close(); } else { MessageBox.Show("Wrong password! Try again"); Password_tf.Clear(); } } else { MessageBox.Show("Username does not exist!! If you dont have account please register!"); Login_tf.Clear(); Password_tf.Clear(); } }