Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using MySql.Data;
  10. using MySql.Data.MySqlClient;
  11. using System.Security.Cryptography;
  12. using System.Web.Security;
  13. using System.Security;
  14. using System.Globalization;
  15. using System.Web.Configuration;
  16.  
  17. namespace WindowsFormsApplication1
  18. {
  19.     public partial class Form3 : Form
  20.     {
  21.         public Form3()
  22.         {
  23.             InitializeComponent();
  24.             poleHeslo.PasswordChar = '*';
  25.         }
  26.  
  27.         private void button1_Click(object sender, EventArgs e)
  28.         {
  29.             FormsAuthentication.Initialize();
  30.             poleJmeno.Text = poleJmeno.Text.ToUpper();
  31.             poleHeslo.Text = poleHeslo.Text.ToUpper();
  32.             string dataForHash = String.Concat(poleJmeno.Text+ ":" +poleHeslo.Text);
  33.             string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(dataForHash, "sha1");
  34.             MySqlCommand cmd = new MySqlCommand();
  35.             string MyConString = "SERVER=localhost;" + "DATABASE=lb_realm;" + "UID=root;" + "PASSWORD=root;";
  36.             MySqlConnection connection = new MySqlConnection(MyConString);
  37.             MySqlCommand command = connection.CreateCommand();
  38.             MySqlDataReader Reader;
  39.             command.CommandText = "SELECT COUNT(id) FROM account WHERE username='" + poleJmeno.Text + "' AND sha_pass_hash='" + hashedPassword + "' ";
  40.             connection.Open();
  41.             Reader = command.ExecuteReader();
  42.             while (Reader.Read())
  43.             {
  44.                 string count = Reader.GetValue(0).ToString();
  45.                 int count_2 = Convert.ToInt32(count);
  46.                 if (count_2 == 0)
  47.                 {
  48.                     poleJmeno.Text = null;
  49.                     poleHeslo.Text = null;
  50.                     MessageBox.Show("Špatné uživatelské jméno nebo heslo!", "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
  51.                 }
  52.                 else
  53.                 {
  54.                     poleJmeno.Text = null;
  55.                     poleHeslo.Text = null;
  56.                     MessageBox.Show("Byl jsi úspěšně přihlášen!", "Přihlášen", MessageBoxButtons.OK, MessageBoxIcon.Information);
  57.                 }
  58.             }
  59.             connection.Close();
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement