Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SQLite;
- using System.Security.Cryptography;
- namespace Sale_on_credit
- {
- public partial class Form1 : MetroFramework.Forms.MetroForm
- {
- Boolean sym;
- string loginDB;
- string passwordDB;
- string login;
- string password;
- string hash_login;
- string hash_password;
- SQLiteCommand cmd;
- SQLiteConnection sqlite_conn;
- SQLiteDataReader reader;
- static int errors=0;
- public Form1()
- {
- InitializeComponent();
- this.StyleManager = metroStyleManager1;
- this.FocusMe();
- sqlite_conn = new SQLiteConnection(getConnectionString());
- sqlite_conn.Open();
- }
- //Метод для получения адреса к БД
- public string getConnectionString()
- {
- string connectionString = @"Data Source=BD_Sales.db;Version=3";
- return connectionString;
- }
- public string MD5(string input)
- {
- MD5 md5 = new MD5CryptoServiceProvider();
- byte[] bytes = md5.ComputeHash(Encoding.Unicode.GetBytes(input));
- string result = BitConverter.ToString(bytes).Replace("-", String.Empty);
- return result.ToLower();
- }
- public string Authorization(string hash_login, string hash_password)
- {
- if (textBox1.Text == "") return "Введите логин пользователя";
- if (textBox2.Text == "") return "Введите пароль пользователя";
- string connectionString = getConnectionString();
- if (textBox1.Text == "admin")
- {
- cmd = new SQLiteCommand("SELECT * FROM admin WHERE id = 1", sqlite_conn);
- reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- if (reader["login"].ToString() == hash_login)
- {
- if (reader["password"].ToString() == hash_password)
- {
- reader.Close();
- sqlite_conn.Close();
- return "*";
- }
- else return "Введен неверный пароль!!!";
- }
- else return "Такого логина не существует!!!";
- }
- reader.Close();
- // sqlite_conn.Close();
- }
- cmd = new SQLiteCommand("SELECT * FROM users WHERE login ='" + hash_login + "'", sqlite_conn);
- reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- if (reader["login"].ToString() == hash_login)
- {
- if (reader["password"].ToString() == hash_password)
- {
- sqlite_conn.Close();
- return "*";
- }
- else return "Введен неверный пароль!!!";
- }
- else return "Такого логина не существует!!!";
- }
- reader.Close();
- return "Введены неверные данные!!!";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string connectionString = getConnectionString();
- SQLiteCommand sqlite_cmd;
- login = textBox1.Text;
- password = textBox2.Text;
- hash_login = MD5(textBox1.Text);
- hash_password = MD5(textBox2.Text);
- string s = Authorization(hash_login,hash_password);
- if (textBox1.Text == "admin" && s == "*")
- {
- Form2 form2 = new Form2();
- form2.Visible = true;
- Visible = false;
- }
- else if (textBox1.Text == "admin" && s != "*")
- {
- MessageBox.Show("Ошибка!!!Проверьте правильность введенных данных!!!");
- }else if (textBox1.Text != "admin" && s == "*")
- {
- Form3 form3 = new Form3();
- form3.Visible = true;
- Visible = false;
- }
- else
- {
- MessageBox.Show("Ошибка!!!Проверьте правильность введенных данных!!!");
- }
- }
- private void Form1_FormClosed(object sender, FormClosedEventArgs e)
- {
- Application.Exit();
- }
- }
- }
Add Comment
Please, Sign In to add comment