private void ButtonAuthClick(object sender, RoutedEventArgs e) { string login = textBoxLogin.Text.Trim(); string password = textBoxPassword.Password.Trim(); if (login.Length < 5) { textBoxLogin.ToolTip = "Длина логина должна быть больше 5 символов!"; textBoxLogin.Background = Brushes.BlueViolet; } else if (password.Length < 5) { textBoxPassword.ToolTip = "Длина пароля должна быть больше 5 символов!"; textBoxPassword.Background = Brushes.BlueViolet; } else { textBoxLogin.ToolTip = ""; textBoxLogin.Background = Brushes.Transparent; textBoxPassword.ToolTip = ""; textBoxPassword.Background = Brushes.Transparent; User authUser = null; using (AppContext db = new AppContext()) { authUser = db.Users.Where(b => b.Login == login && b.Password == password ).FirstOrDefault(); } if (authUser != null) { MessageBox.Show("Все правильно!"); UserPageWindow userPage = new UserPageWindow(); userPage.Show(); Hide(); } else { MessageBox.Show("Все неправильно"); } } }
private void Button_Auth_Click(object sender, RoutedEventArgs e) { string log = LoginLabel.Text.Trim(); string pass = PassLabel.Password.Trim(); if (log.Length < 5) { LoginLabel.ToolTip = "Login must be more than 5 characters!"; LoginLabel.Background = Brushes.MediumPurple; } else if (pass.Length < 5) { PassLabel.ToolTip = "Password must be more than 5 characters!"; PassLabel.Background = Brushes.MediumPurple; } else { LoginLabel.ToolTip = ""; LoginLabel.Background = Brushes.Transparent; PassLabel.ToolTip = ""; PassLabel.Background = Brushes.Transparent; User authUser = null; using (ApplicationContext context = new ApplicationContext()) { authUser = context.Users.Where(b => b.Login == log && b.Pass == pass).FirstOrDefault(); } if (authUser != null) { MessageBox.Show("All is good!"); UserPageWindow userPage = new UserPageWindow(); userPage.Show(); Hide(); } else { MessageBox.Show("Wrong data!"); } } }