daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Jan 20th, 2017 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Security.Cryptography;
  11. using System.Data.OleDb;
  12.  
  13. namespace EncyrptedPassword
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void Form1_Load(object sender, EventArgs e)
  23.         {
  24.  
  25.         }
  26.  
  27.         private void button1_Click(object sender, EventArgs e)
  28.         {
  29.             string Username = "", GuessedPasswordHashed = "", CorrectPassword = "", UsernameFromDatabse = "";
  30.             Username = txt_Username.Text;
  31.             GuessedPasswordHashed = GenerateHash(txt_Password.Text);
  32.            
  33.              GetUsername(ref UsernameFromDatabse, ref CorrectPassword, Username);
  34.             if (GuessedPasswordHashed == CorrectPassword && Username == UsernameFromDatabse)
  35.             {
  36.                 Successful frm = new Successful();
  37.                 frm.Show();
  38.             }
  39.             else
  40.             {
  41.                 txt_Password.Text = "";
  42.                 txt_Username.Text = "";
  43.                 MessageBox.Show("Please enter correct Username or Password");
  44.             }
  45.         }
  46.         private string GenerateHash(string SourceText)
  47.         {
  48.            
  49.             UnicodeEncoding Ue = new UnicodeEncoding();
  50.             byte[] ByteSourceText = Ue.GetBytes(SourceText);
  51.             MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
  52.             byte[] ByteHash = MD5.ComputeHash(ByteSourceText);
  53.             return Convert.ToBase64String(ByteHash);
  54.         }
  55.         private void GetUsername(ref string UsernameFromDatabse, ref string CorrectPassword, string Username)
  56.         {
  57.             clsDBConnector dbConnector = new clsDBConnector();
  58.             OleDbDataReader dr;
  59.             string sqlStr;
  60.             dbConnector.Connect();
  61.             sqlStr = "SELECT        Username, [Password]" +
  62.                   " FROM            Login" +
  63.                   " WHERE        Username = '" + Username + "'";
  64.             dr = dbConnector.DoSQL(sqlStr);
  65.             while (dr.Read())
  66.             {
  67.                 UsernameFromDatabse = Convert.ToString(dr[0]);
  68.                 CorrectPassword = Convert.ToString(dr[1]);
  69.                
  70.             }
  71.         }
  72.  
  73.         private void button2_Click(object sender, EventArgs e)
  74.         {
  75.             if (txt_Password.UseSystemPasswordChar == true)
  76.             {
  77.                 txt_Password.UseSystemPasswordChar = false;
  78.             }
  79.             else
  80.             {
  81.                 txt_Password.UseSystemPasswordChar = true;
  82.             }
  83.         }
  84.     }
  85.  
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top