Anonim_999

da

Jun 9th, 2024
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Data.SqlClient;
  4.  
  5. namespace PharmacyDubak
  6. {
  7.     public partial class AuthorizationForm : Form
  8.     {
  9.         private DataBaseConnection _dataBaseConnection;
  10.         private bool _isPasswordShow = false;
  11.  
  12.         public AuthorizationForm()
  13.         {
  14.             InitializeComponent();
  15.             _dataBaseConnection = new DataBaseConnection();
  16.         }
  17.  
  18.         private void LoginButton_Click(object sender, EventArgs e)
  19.         {
  20.             string login = LoginTextBox.Text;
  21.             string password = PasswordTextBox.Text;
  22.  
  23.             if (IsValidUser(login, password))
  24.             {
  25.                 MessageBox.Show("Вы успешно вошли!", "Успешно!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  26.                 MainForm mainForm = new MainForm();
  27.                 mainForm.Show();
  28.                 Hide();
  29.             }
  30.             else
  31.             {
  32.                 MessageBox.Show("Вы ввели неверно логин или пароль!", "Неудача!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  33.             }
  34.         }
  35.  
  36.         private bool IsValidUser(string username, string password)
  37.         {
  38.             string query = "IF EXISTS (SELECT * FROM sys.sql_logins WHERE name = @username AND PWDCOMPARE(@password, password_hash) = 1) SELECT 1 ELSE SELECT 0";
  39.             SqlCommand command = new SqlCommand(query, _dataBaseConnection.GetConnection());
  40.             _dataBaseConnection.OpenConnection();
  41.             command.Parameters.AddWithValue("@username", username);
  42.             command.Parameters.AddWithValue("@password", password);
  43.             int result = (int)command.ExecuteScalar();
  44.             return result == 1;
  45.         }
  46.  
  47.         private void RegistrationLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  48.         {
  49.             LoginButton.Enabled = false;
  50.             LoginButton.Visible = false;
  51.             LoginTextBox.Text = "";
  52.             PasswordTextBox.Text = "";
  53.         }
  54.  
  55.         private void LoginLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  56.         {
  57.             LoginButton.Visible = true;
  58.             LoginButton.Enabled = true;
  59.             LoginTextBox.Text = "";
  60.             PasswordTextBox.Text = "";
  61.         }
  62.  
  63.         private void button1_Click(object sender, EventArgs e)
  64.         {
  65.             if (_isPasswordShow == false)
  66.             {
  67.                 PasswordTextBox.PasswordChar = default;
  68.                 _isPasswordShow = true;
  69.                 Shower.Text = "O";
  70.             }
  71.             else
  72.             {
  73.                 PasswordTextBox.PasswordChar = '*';
  74.                 _isPasswordShow = false;
  75.                 Shower.Text = "Ø";
  76.             }
  77.         }
  78.     }
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment