maximkustreev

Untitled

Jul 8th, 2012
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System.Drawing;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.Security.Cryptography;
  6. //  in Future TODO:
  7. //  *   MD5-hashing password of users;
  8. //  *   SQL-users, -logins;
  9. //  *   create users in Windows-Forms;
  10. namespace gild
  11. {
  12.  
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void button1_Click(object sender, EventArgs e)
  21.         {
  22.             Form2 f2 = new Form2();    
  23.             string log, pass;
  24.             string username=null, code=null;  
  25.      
  26.             SqlConnection conn = new SqlConnection("Data Source=USER12\\SQLEXPRESS;Initial Catalog=testdata;Integrated Security=True;");          
  27.             conn.Open();
  28.             SqlCommand cmd = new SqlCommand("select * from testdata.dbo.logins where mode='true'", conn);
  29.             SqlDataReader reader = cmd.ExecuteReader();
  30.             while (reader.Read())
  31.             {
  32.                 username = (string)reader[0];
  33.                 code = (string)reader[1];
  34.  
  35.                 log = username.ToString();
  36.                 pass = code.ToString();
  37.                 //  *   *   *   *   *   *   *   *   *   *
  38.                //   *   gethash
  39.                 MD5 md5Hasher = MD5.Create();
  40.                 byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(textBox2.Text));
  41.  
  42.                 StringBuilder sBuilder = new StringBuilder();
  43.  
  44.                 for (int i = 0; i < data.Length; i++)
  45.                  {
  46.                     sBuilder.Append(data[i].ToString("x2"));
  47.                  }
  48.                 string hashkey = sBuilder.ToString();
  49.                 //  *   ending gethash
  50.                 //  *   *   *   *   *   *   *   *   *   *    
  51.    
  52.                 //  *   verifyhash
  53.                      
  54.                 StringComparer comparer = StringComparer.OrdinalIgnoreCase;
  55.  
  56.                  if (0 == comparer.Compare(hashkey, pass))
  57.                     {
  58.             ...блабла ...еще дописываю )))
  59.             }
Advertisement
Add Comment
Please, Sign In to add comment