private void button1_Click(object sender, EventArgs e) { try { #region AES string usrencrypted = AesCryp.Encrypt(textBox1.Text); #endregion AES #region MD5 string username = usrencrypted; byte[] encodedPassword = new UTF8Encoding().GetBytes(username); byte[] hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedPassword); string encoded = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower(); #endregion MD5 #region ReadPasswordWithVibes string line = File.ReadLines("Users\\" + encoded + "\\salt.txt").Skip(1).Take(1).First(); string DecryptKey = AesCryp.Decrypt(line); AesCryp.Key = DecryptKey; string pwdencrypted = AesCryp.Encrypt(textBox2.Text); AesCryp.Key = "5j2gfx0y5m9mb1x6ejtz384p9b4hf5nq"; #endregion ReadPasswordWithVibes #region Login&CheckDir string dirName = new DirectoryInfo(@"Users\" + encoded).Name; if (Directory.Exists(@"Users\" + encoded)) { if (encoded == dirName) { #region SaltHash string line1 = File.ReadLines("Users\\" + encoded + "\\salt.txt").First(); string readpwd = File.ReadAllText("Users\\" + encoded + "\\password.txt"); string decryptSalt = AesCryp.Decrypt(line1); int x = 0; Int32.TryParse(decryptSalt, out x); SaltHash pwd = new SaltHash(pwdencrypted, x); string strHashedPassword = pwd.ComputeSaltedHash(); SaltHash usr = new SaltHash(usrencrypted, x); string strHashedUsername = usr.ComputeSaltedHash(); string encryptUsername = AesCryp.Encrypt(strHashedUsername); #endregion SaltHash #region CheckUsername string line3 = File.ReadLines("Users\\" + encoded + "\\salt.txt").Skip(2).Take(1).First(); #endregion CheckUsername if (readpwd == strHashedPassword) { if (line3 == encryptUsername) { #region LoadMain label3.Text = encoded; Main main = new Main(); main.Text = "Current User: "******"Password or Username incorrect!"); } } else { MessageBox.Show("Password or Username incorrect!"); } } else { return; } } else { MessageBox.Show("Password or Username incorrect!"); } #endregion Login&CheckDir } catch { #region ErrorMessage MessageBox.Show("An Error occured!"); #endregion ErrorMessage } }
private void button1_Click(object sender, EventArgs e) { #region AES string usrencrypted = AesCryp.Encrypt(textBox1.Text); #endregion AES #region MD5 string username = usrencrypted; byte[] encodedPassword = new UTF8Encoding().GetBytes(username); byte[] hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedPassword); string encoded = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower(); #endregion MD5 #region DecryptAES string line = File.ReadLines("Users\\" + encoded + "\\salt.txt").Skip(1).Take(1).First(); string reset = File.ReadAllText("Users\\" + encoded + "\\reset.txt"); string DecryptKey = AesCryp.Decrypt(line); AesCryp.Key = DecryptKey; string pwdencrypted = AesCryp.Encrypt(textBox3.Text); AesCryp.Key = "5j2gfx0y5m9mb1x6ejtz384p9b4hf5nq"; #endregion DecryptAES #region Salt string readSalt = File.ReadLines("Users\\" + encoded + "\\salt.txt").Skip(0).Take(1).First(); string decryptSalt = AesCryp.Decrypt(readSalt); int x = 0; Int32.TryParse(decryptSalt, out x); SaltHash usr = new SaltHash(pwdencrypted, x); string strHashedReset = usr.ComputeSaltedHash(); #endregion Salt if (strHashedReset == reset) { if (textBox2.Text == "") { MessageBox.Show("You have to choose a new Password!"); } else { #region AES string ReadLine = File.ReadLines("Users\\" + encoded + "\\salt.txt").Skip(1).Take(1).First(); string DecryptLine = AesCryp.Decrypt(ReadLine); AesCryp.Key = DecryptLine; string PasswordEncrypted = AesCryp.Encrypt(textBox2.Text); AesCryp.Key = "5j2gfx0y5m9mb1x6ejtz384p9b4hf5nq"; #endregion AES #region SaltHash string readSalt1 = File.ReadAllText("Users\\" + encoded + "\\salt.txt"); string decryptSalt1 = AesCryp.Decrypt(readSalt); int i = 0; Int32.TryParse(decryptSalt, out i); SaltHash pwd = new SaltHash(PasswordEncrypted, i); string strHashedPassword = pwd.ComputeSaltedHash(); #endregion SaltHash File.WriteAllText("Users\\" + encoded + "\\password.txt", strHashedPassword); MessageBox.Show("Password Successfully changed!"); } } else { MessageBox.Show("Reset is Incorrect!"); } }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") { MessageBox.Show("Fields cannot be blank!"); } else { #region AES string UserEncrypted = AesCryp.Encrypt(textBox1.Text); string GenerateAesKey = RandomString(); AesCryp.Key = GenerateAesKey; string PasswordEncrypted = AesCryp.Encrypt(textBox2.Text); string ResetEncrypted = AesCryp.Encrypt(textBox3.Text); AesCryp.Key = "5j2gfx0y5m9mb1x6ejtz384p9b4hf5nq"; string EncryptedAesKey = AesCryp.Encrypt(GenerateAesKey); #endregion AES #region MD5 string username = UserEncrypted; byte[] encodedPassword = new UTF8Encoding().GetBytes(username); byte[] hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedPassword); string encoded = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower(); #endregion MD5 if (Directory.Exists(@"Users\" + encoded)) { #region UserExistsWindow MessageBox.Show("User Already Exists"); #endregion UserExistsWindow } else { #region CreateSaltFile Directory.CreateDirectory(@"Users\" + encoded); int mySalt = SaltHash.CreateRandomSalt(); string stringsalt = mySalt.ToString(); string saltencrypted = AesCryp.Encrypt(stringsalt); File.WriteAllText("Users\\" + encoded + "\\salt.txt", saltencrypted); #endregion CreateSaltFile #region SaltHash string readSalt = File.ReadAllText("Users\\" + encoded + "\\salt.txt"); string decryptSalt = AesCryp.Decrypt(readSalt); int x = 0; Int32.TryParse(decryptSalt, out x); SaltHash usr = new SaltHash(UserEncrypted, x); string strHashedUsername = usr.ComputeSaltedHash(); SaltHash pwd = new SaltHash(PasswordEncrypted, x); string strHashedPassword = pwd.ComputeSaltedHash(); SaltHash rst = new SaltHash(ResetEncrypted, x); string strHashedReset = rst.ComputeSaltedHash(); string encryptUsername = AesCryp.Encrypt(strHashedUsername); #endregion SaltHash #region Create&Write File.WriteAllText("Users\\" + encoded + "\\password.txt", strHashedPassword); File.WriteAllText("Users\\" + encoded + "\\reset.txt", strHashedReset); File.AppendAllText("Users\\" + encoded + "\\salt.txt", Environment.NewLine); File.AppendAllText("Users\\" + encoded + "\\salt.txt", EncryptedAesKey); File.AppendAllText("Users\\" + encoded + "\\salt.txt", Environment.NewLine); File.AppendAllText("Users\\" + encoded + "\\salt.txt", encryptUsername); Directory.CreateDirectory("Users\\" + encoded + "\\Combos"); MessageBox.Show("User Created Succefully!"); #endregion Create&Write } } }