/// <summary> /// Checks user input and adds new user to the database /// </summary> private void Add_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrWhiteSpace(newUserName) || string.IsNullOrWhiteSpace(newUserLogin) || string.IsNullOrWhiteSpace(newUserPassword)) { throw new EmptyFieldException(); } if (!userDB.CheckLogin(newUserLogin)) { throw new UserDataFieldException(); } if (userDB.AddUser(newUserLogin, newUserPassword, newUserName)) { MessageBox.Show("Пользователь успешно добавлен", "Выполнено"); this.DialogResult = true; } else { MessageBox.Show("Неопознанная ошибка добавления пользователя.", "Ошибка"); this.DialogResult = true; } } catch (UserDataFieldException exception) { MessageBox.Show(exception.ErrorMessageExist, exception.Error); LoginTextBox.Clear(); } catch (EmptyFieldException exception) { MessageBox.Show(exception.ErrorMessage, exception.Error); } }
private void LoginButton_Click(object sender, EventArgs e) { if (registration == true) { if (LoginTextBox.Text != "" && PasswordTextBox.Text != "" && LastNameTextBox.Text != "" && EmailTextBox.Text != "" && RobotCheckBox.Checked == true && GenderComboBox.SelectedItem != null && BirthDateTimePicker.Value != null) { Users.Add(new User(LoginTextBox.Text, LastNameTextBox.Text, PasswordTextBox.Text, EmailTextBox.Text, GenderComboBox.SelectedItem, Convert.ToString(BirthDateTimePicker.Value))); folderBrowserDialog1.ShowDialog(); File.AppendAllText(folderBrowserDialog1.SelectedPath + "\\Data.txt", $"Имя: {LoginTextBox.Text}, Фамилия: {LastNameTextBox.Text}, Электронная почта: {PasswordTextBox.Text}, Пароль: {EmailTextBox.Text}, Пол: {GenderComboBox.SelectedItem}, Дата рождения: {BirthDateTimePicker.Value}.\n"); LoginTextBox.Clear(); PasswordTextBox.Clear(); LastNameTextBox.Clear(); EmailTextBox.Clear(); RobotCheckBox.Checked = false; GenderComboBox.SelectedItem = ""; BirthDateTimePicker.Value = DateTime.Now; } } else { for (int i = 0; i < Users.Count; i++) { if (LoginTextBox.Text == User.GetInfo(Users[i], 0) && PasswordTextBox.Text == User.GetInfo(Users[i], 3)) { Sign sign = new Sign(User.GetInfo(Users[i], 0)); sign.TextLabel.Text = "Авторизация прошла успешно!"; sign.Show(); return; } } Sign form2 = new Sign(); form2.TextLabel.Text = "Неправильный логин или пароль"; form2.Show(); } }
private void EnterButton_Click(object sender, EventArgs e) { string password = ""; if (LoginTextBox.Text == " " || PasswordTextBox.Text == " ") { MessageBox.Show("Не все поля заполнены"); LoginTextBox.Focus(); } int count = 0; string command = "Select Пароль from Пользователи Where Имя_Пользователя = @login"; SqlParameter p1 = new SqlParameter("login", LoginTextBox.Text); var reader = StaticProcesser.GetReader(command, p1); while (reader.Read()) { count++; try { password = reader.GetString(0); password = password.Replace(Environment.NewLine, ""); } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } } if (count == 0) { MessageBox.Show("Такого пользователя не существует"); LoginTextBox.Clear(); LoginTextBox.Focus(); PasswordTextBox.Clear(); reader.Close(); StaticProcesser.CloseConnection(); } else if (count == 1) { reader.Close(); StaticProcesser.CloseConnection(); string inputedPass = StaticProcesser.ComputeHash(PasswordTextBox.Text, new MD5CryptoServiceProvider()); if (password == inputedPass) { User.Login = LoginTextBox.Text; User.Access = 1; if (User.Login == "admin") { User.Access = 2; } this.Dispose(); } else { MessageBox.Show("Пароль введён не верно"); PasswordTextBox.Clear(); PasswordTextBox.Focus(); } } }
private void SignInButton_Click(object sender, RoutedEventArgs e) { if (!service.SignIn(LoginTextBox.Text, PasswordBox.Password, out string message, out Employee employee)) { MessageBox.Show(message); LoginTextBox.Clear(); PasswordBox.Clear(); }
// Регистрация со всеми проверками private void RegistrationButton_Click(object sender, EventArgs e) { Checking checking = new Checking(); if (!checking.Login(LoginTextBox.Text)) { PromptLabel.Text = "Не верный формат имени пользователя"; } else if (!checking.Email(EmailTextBox.Text)) { PromptLabel.Text = "Не верный формат e-mail"; } else if (!checking.Password(PasswordTextBox.Text)) { PromptLabel.Text = "Не верный формат пароля"; } else if (PasswordTextBox.Text.CompareTo(RepeatPasswordTextBox.Text) != 0) { PromptLabel.Text = "Пароли не совпадают"; } else if (!checking.LoginInBase(LoginTextBox.Text)) { PromptLabel.Text = "Пользователь уже существует или проблема с базой"; } else { string path = @"logins\" + LoginTextBox.Text[0] + ".txt"; string text = LoginTextBox.Text + "|" + EmailTextBox.Text + "|" + PasswordTextBox.Text + "\r\n"; try { File.AppendAllText(path, text); path = @"users_lists\" + LoginTextBox.Text + ".txt"; using (StreamWriter sw = new StreamWriter(path)) { sw.Write(""); } } catch { MessageBox.Show("Простите, в работе с базой пользователей что-то пошло не так"); return; } PasswordTextBox.Clear(); RepeatPasswordTextBox.Clear(); LoginTextBox.Clear(); EmailTextBox.Clear(); PromptLabel.Text = "Вы успешно зарегистрированы"; } }
private void AuthenticationComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (AuthenticationComboBox.SelectedIndex == 0) { LoginTextBox.Clear(); LoginTextBox.ReadOnly = true; PWDTextBox.Clear(); PWDTextBox.ReadOnly = true; } else { LoginTextBox.ReadOnly = false; PWDTextBox.ReadOnly = false; } }
private void RegisterButton_Click(object sender, RoutedEventArgs e) { try { mParent.mUser = mParent.mManager.Register( LoginTextBox.Text, Password.Password, NicknameTextBox.Text ); } catch (UserNotRegisteredException) { LoginTextBox.Clear(); // MessageBox } }
private void RegistrationButton_Click(object sender, RoutedEventArgs e) { string login = LoginTextBox.Text; string onepwd = OnePasswordBox.Password; string twopwd = TwoPasswordBox.Password; if (login.Length != 0 && onepwd == twopwd) { if (CheckLogin(login)) { string hash_login = GetHash(login); string hash_pwd = GetHash(onepwd + hash_login); string hash_sn = GetHash(serial_numbers[0] + hash_login); string data_auth = login + ":" + hash_pwd + ":" + hash_sn + ":"; //Запись в файл using (FileStream fstream = new FileStream("database", FileMode.Append)) { byte[] array = System.Text.Encoding.Default.GetBytes(data_auth); fstream.Write(array, 0, array.Length); } MessageBox.Show("Регистрация успешно пройдена!", "", MessageBoxButton.OK, MessageBoxImage.Information); LoginTextBox.Clear(); OnePasswordBox.Clear(); TwoPasswordBox.Clear(); CheckButton.IsEnabled = true; RegistrationButton.IsEnabled = false; } else { MessageBox.Show("Выбранный логин используется!", "", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { if (login.Length == 0) { MessageBox.Show("Введите логин!", "", MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBox.Show("Пароли не совпадают!", "", MessageBoxButton.OK, MessageBoxImage.Warning); } } }
protected override void OnExit(object sender, RoutedEventArgs e) { base.OnExit(sender, e); _changeNicknameExplicit = false; LoginTextBox.Clear(); PasswordTextBox.Clear(); NicknameTextBox.Clear(); if (!IsOnExitActive) { e.Handled = true; return; } }
private void LoginButton_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(LoginTextBox.Text) && !string.IsNullOrEmpty(PasswordBox.Password)) { if (service.SignIn(LoginTextBox.Text, PasswordBox.Password, out string message, out User user)) { var userWindow = new UserWindow(service, user); Hide(); userWindow.ShowDialog(); Show(); } else { MessageBox.Show(message); LoginTextBox.Clear(); PasswordBox.Clear(); LoginTextBox.Focus(); } }
protected override void OnExit(object sender, RoutedEventArgs e) { base.OnExit(sender, e); _autoUpdateStatusesTimer.Stop(); LoginTextBox.Clear(); PasswordTextBox.Clear(); RememberMeCheckBox.IsChecked = false; OpenStoredAccountsButton.IsChecked = false; if (!IsOnExitActive) { e.Handled = true; return; } }
private async void AddButton_Click(object sender, EventArgs e) { if (InsertErrorLabel.Visible) { InsertErrorLabel.Visible = false; } if ((String.IsNullOrEmpty(LoginTextBox.Text) || String.IsNullOrEmpty(PasswordTextBox.Text) || String.IsNullOrEmpty(DescriptionOfAccountTextBox.Text)) && ((String.IsNullOrWhiteSpace(LoginTextBox.Text) || String.IsNullOrWhiteSpace(PasswordTextBox.Text) || String.IsNullOrWhiteSpace(DescriptionOfAccountTextBox.Text)))) { InsertErrorLabel.Visible = true; } else { SqlCommand command = new SqlCommand("INSERT INTO [AccountsData](Description_of_account, Login_of_account, Pass_of_account) VALUES (@Description_of_account, @Login_of_account, @Pass_of_account)", sqlCon); command.Parameters.AddWithValue("Description_of_account", DescriptionOfAccountTextBox.Text); command.Parameters.AddWithValue("Login_of_account", LoginTextBox.Text); command.Parameters.AddWithValue("Pass_of_account", PasswordTextBox.Text); await command.ExecuteNonQueryAsync(); LoginTextBox.Clear(); PasswordTextBox.Clear(); DescriptionOfAccountTextBox.Clear(); } }