Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.84 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Data.SqlClient;
  7. using MySql.Data.MySqlClient;
  8. using System.IO;
  9.  
  10. namespace WindowsFormsApp5
  11. {
  12.     public partial class logowanie : Form
  13.  
  14.     {
  15.  
  16.         MySqlConnection polaczenie = new MySqlConnection("server=sql.djkelvin.nazwa.pl; user=djkelvin_drukarnia; password=ZAQ!2wsx; database=djkelvin_drukarnia");
  17.         MySqlCommand komenda;
  18.         string zapytanieSQL = "";
  19.  
  20.         public logowanie()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void haslo_Click(object sender, EventArgs e)
  26.         {
  27.  
  28.         }
  29.  
  30.         private void Form1_Load(object sender, EventArgs e)
  31.         {
  32.  
  33.         }
  34.  
  35.         private void wejscie_Click(object sender, EventArgs e)
  36.         {
  37.             try
  38.             {
  39.                 if (polaczenie.State == ConnectionState.Closed)
  40.                     polaczenie.Open();
  41.  
  42.                 string haslo = "";
  43.                 using (MD5 md5 = MD5.Create())
  44.                 {
  45.                     haslo = GetMD5Hash(md5, haslotb2.Text);
  46.                 }
  47.  
  48.  
  49.                 zapytanieSQL = string.Format("select count(Id) from uzytkownicy where Login = '{0}' and Haslo = '{1}'", logintb1.Text, haslo);
  50.                 komenda = new MySqlCommand(zapytanieSQL, polaczenie);
  51.                 int wartosc = Convert.ToInt32(komenda.ExecuteScalar());
  52.  
  53.                 if (wartosc == 0)
  54.                    
  55.                
  56.                 MessageBox.Show("Brak takiego użytkownika", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
  57.                                                                                                                      
  58.            
  59.                
  60.                
  61.                
  62.                
  63.  
  64.                 else if (wartosc > 0)
  65.                     this.Close();
  66.                     new strona().Show();
  67.  
  68.                    
  69.  
  70.  
  71.  
  72.             }
  73.             catch (Exception ex)
  74.             {
  75.  
  76.                 string byk = string.Format("Problem podczas logowania:\n'{0}'");
  77.                 MessageBox.Show(byk, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
  78.             }
  79.             finally
  80.             {
  81.                 polaczenie.Close();
  82.             }
  83.  
  84.  
  85.             if (string.IsNullOrWhiteSpace(logintb1.Text) || string.IsNullOrWhiteSpace(haslotb2.Text))
  86.             {
  87.  
  88.                 MessageBox.Show("Wszystkie pola muszą być wypełnione", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
  89.                 return;
  90.  
  91.             }
  92.            
  93.                
  94.         }
  95.  
  96.         private void textBox2_TextChanged(object sender, EventArgs e)
  97.         {
  98.  
  99.         }
  100.  
  101.         private void textBox1_TextChanged(object sender, EventArgs e)
  102.         {
  103.  
  104.         }
  105.  
  106.         private void nazwa_Click(object sender, EventArgs e)
  107.         {
  108.  
  109.         }
  110.  
  111.         private void exit_Click(object sender, EventArgs e)
  112.         {
  113.             this.Close();
  114.         }
  115.  
  116.         private void exit_Click_1(object sender, EventArgs e)
  117.         {
  118.             this.Close();
  119.         }
  120.  
  121.         private void label1_Click(object sender, EventArgs e)
  122.         {
  123.  
  124.         }
  125.  
  126.         private void pictureBox1_Click(object sender, EventArgs e)
  127.         {
  128.  
  129.         }
  130.  
  131.         private void button1_Click(object sender, EventArgs e)
  132.         {
  133.             new Form9().Show();
  134.             this.Hide();
  135.         }
  136.  
  137.         string GetMD5Hash(MD5 hash, string input)
  138.         {
  139.             byte[] tab = hash.ComputeHash(Encoding.UTF8.GetBytes(input));
  140.  
  141.             StringBuilder sBuilder = new StringBuilder();
  142.             for (int i = 0; i < tab.Length; i++)
  143.                 sBuilder.Append(tab[i].ToString("x2"));
  144.  
  145.             return sBuilder.ToString();
  146.  
  147.  
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement