Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace PharmacyDubak
- {
- public partial class AuthorizationForm : Form
- {
- private DataBaseConnection _dataBaseConnection;
- private bool _isPasswordShow = false;
- public AuthorizationForm()
- {
- InitializeComponent();
- _dataBaseConnection = new DataBaseConnection();
- }
- private void LoginButton_Click(object sender, EventArgs e)
- {
- string login = LoginTextBox.Text;
- string password = PasswordTextBox.Text;
- if (IsValidUser(login, password))
- {
- MessageBox.Show("Вы успешно вошли!", "Успешно!", MessageBoxButtons.OK, MessageBoxIcon.Information);
- MainForm mainForm = new MainForm();
- mainForm.Show();
- Hide();
- }
- else
- {
- MessageBox.Show("Вы ввели неверно логин или пароль!", "Неудача!", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private bool IsValidUser(string username, string password)
- {
- string query = "IF EXISTS (SELECT * FROM sys.sql_logins WHERE name = @username AND PWDCOMPARE(@password, password_hash) = 1) SELECT 1 ELSE SELECT 0";
- SqlCommand command = new SqlCommand(query, _dataBaseConnection.GetConnection());
- _dataBaseConnection.OpenConnection();
- command.Parameters.AddWithValue("@username", username);
- command.Parameters.AddWithValue("@password", password);
- int result = (int)command.ExecuteScalar();
- return result == 1;
- }
- private void RegistrationLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- LoginButton.Enabled = false;
- LoginButton.Visible = false;
- LoginTextBox.Text = "";
- PasswordTextBox.Text = "";
- }
- private void LoginLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- LoginButton.Visible = true;
- LoginButton.Enabled = true;
- LoginTextBox.Text = "";
- PasswordTextBox.Text = "";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (_isPasswordShow == false)
- {
- PasswordTextBox.PasswordChar = default;
- _isPasswordShow = true;
- Shower.Text = "O";
- }
- else
- {
- PasswordTextBox.PasswordChar = '*';
- _isPasswordShow = false;
- Shower.Text = "Ø";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment