Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 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.  
  16. namespace WindowsFormsApplication1
  17. {
  18.     public partial class Form3 : Form
  19.     {
  20.         public Form3()
  21.         {
  22.             InitializeComponent();
  23.             poleHeslo.PasswordChar = '*';
  24.         }
  25.  
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  28.             FormsAuthentication.Initialize();
  29.             //string hashedpwd = String.Concat(poleJmeno.Text, poleHeslo.Text);
  30.             //string hashedPwds = FormsAuthentication.HashPasswordForStoringInConfigFile(hashedpwd, "sha1");
  31.             poleJmeno.Text = poleJmeno.Text.ToUpper(new CultureInfo("en-US", false));
  32.             poleHeslo.Text = poleHeslo.Text.ToUpper(new CultureInfo("en-US", false));
  33.             string dataForHash = String.Concat(poleJmeno.Text, ":");
  34.             string dataForHash2 = String.Concat(dataForHash, poleHeslo.Text);
  35.             string hashedPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(dataForHash2, "sha1");
  36.             string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(poleHeslo.Text, "sha1");
  37.             MySqlCommand cmd = new MySqlCommand();
  38.             string MyConString = "SERVER=localhost;" + "DATABASE=lb_realm;" + "UID=root;" + "PASSWORD=root;";
  39.             MySqlConnection connection = new MySqlConnection(MyConString);
  40.             MySqlCommand command = connection.CreateCommand();
  41.             MySqlDataReader Reader;
  42.             command.CommandText = "SELECT COUNT(id) FROM account WHERE username='" + poleJmeno.Text + "' AND sha_pass_hash='" + hashedPwd + "' ";
  43.             connection.Open();
  44.             Reader = command.ExecuteReader();
  45.             while (Reader.Read())
  46.             {
  47.                 string thisrow = "";
  48.                 for (int i = 0; i < Reader.FieldCount; i++)
  49.                     thisrow += Reader.GetValue(i).ToString() + ",";
  50.                 listBox1.Items.Add(thisrow);
  51.             }
  52.             connection.Close();
  53.             poleTest.Text = hashedPwd.ToLower();
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement