Advertisement
Lynnstrum

Password Hash

Aug 14th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. namespace TexByte
  2. {
  3.     public partial class Form2 : Form
  4.     {
  5.         public Form2()
  6.         {
  7.             InitializeComponent();
  8.         }
  9.  
  10.         private void button1_Click(object sender, EventArgs e)
  11.         {
  12.             string password = textBox2.Text;
  13.             string mySalt = BCrypt.Net.BCrypt.GenerateSalt();
  14.  
  15.             var start = DateTime.UtcNow;
  16.             var hashed = BCrypt.Net.BCrypt.HashPassword(password, mySalt);
  17.             var end = DateTime.UtcNow;
  18.  
  19.             Console.WriteLine("hash length is {0} chars", hashed.Length);
  20.             Console.WriteLine("Processing time is {0} with workFactor {1}", end - start, mySalt);
  21.             Console.WriteLine("Hashed password: {0} ", hashed);
  22.             Console.WriteLine("correct password {0}", BCrypt.Net.BCrypt.Verify("021495", hashed));
  23.             Console.WriteLine("incorrect password {0}", BCrypt.Net.BCrypt.Verify("PASSWORd", hashed));
  24.  
  25.             MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;Initial Catalog='login';username=root;password=password");
  26.             MySqlDataAdapter adapter;
  27.             DataTable table = new DataTable();
  28.  
  29.             adapter = new MySqlDataAdapter("SELECT `username`, `password` FROM `members` WHERE `username` = '" + textBox1.Text + "' AND `password` = '" + password + "'", connection);
  30.             adapter.Fill(table);
  31.  
  32.             if (table.Rows.Count <= 0)
  33.             {
  34.                 MessageBox.Show("Invalid Username or Password", "MySQL Login",
  35.                     MessageBoxButtons.OK, MessageBoxIcon.Warning);
  36.             }
  37.  
  38.             else
  39.             {
  40.                 MessageBox.Show("Connection to database successful", "MySQL Login",
  41.                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  42.             }
  43.         }
  44.         private void Form2_Load(object sender, EventArgs e)
  45.         {
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement