Hash kodu ile login işlemini nasıl yaparım?

yalcinos (1) 9 yıl önce sordu

Yukarıdaki hash kodunu login ekranında Txt dosyası içinde bulunan kullanıcı adı ve şifre ile kontrol edip doğruysa başka bir forma geçmesini nasıl sağlarım?

byte[] p = ASCIIEncoding.ASCII.GetBytes(userPassword);
            byte[] a6 = ASCIIEncoding.ASCII.GetBytes(userAccountID);

            byte totVector = 0;

            for (int i = 0; i < 8; i++)
            {
                totVector = (byte)(totVector + p[i]);
            }

            byte[] a_concat = new byte[2];
            a_concat[0] = (byte)((p[6] * totVector) % 256);
            a_concat[1] = (byte)((p[7] * totVector) % 256);

            byte[] a = new byte[8];
            for (int i = 0; i < 6; i++)
            {
                a[i] = a6[i];
            }
            a[6] = a_concat[0];
            a[7] = a_concat[1];

            byte[] h = new byte[8];
            string hashedUserPassword = "";

            for (int i = 0; i < 8; i++)
            {
                if (i == 0 || i == 2) h[i] = (byte)((p[i] << 1) ^ a[i]);
                else if (i == 3 || i == 5) h[i] = (byte)((p[i] >> 2) ^ a[i]);
                else h[i] = (byte)(p[i] ^ a[i]);

                hashedUserPassword += h[i].ToString("X2");
            }

            return hashedUserPassword;

 

Toplam 1 cevap


beytullahakyuz (181) 8 yıl önce cevapladı

public static string md5hash(string Metin)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] ba = Encoding.UTF8.GetBytes(Metin);
            ba = md5.ComputeHash(ba);

            StringBuilder sb = new StringBuilder();
            foreach (byte b in ba)
            {
                sb.Append(b.ToString("x2").ToLower());
            }

            return sb.ToString();
        }

 private void Button1_Click(object sender, EventArgs e)
        {

              string path = Path.GetDirectoryName(Application.ExecutablePath) + @"\ayar.txt";

              string password = File.ReadAllText(path);

              if (password == md5hash(textBox1.Text))

                    MessageBox.Show("Başarılı. Giriş yapılıyor...");

              else

                    MessageBox.Show("Hatalı şifre.!");

        }