private void BtnOk_Click(object sender, EventArgs e) { LoggedInUser = usersRepository.Get(tbUserName.Text); if (LoggedInUser == null) { return; } ushort xorPwdPart1 = Byte.MinValue; while (xorPwdPart1 <= Byte.MaxValue) { ushort xorPwdPart2 = Byte.MinValue; while (xorPwdPart2 <= Byte.MaxValue) { var xorPassword = new byte[] { (byte)xorPwdPart1, (byte)xorPwdPart2 }; var byteXorCipher = new ByteXorCipher(xorPassword); var saltedPasswordHash = Hash.GetSaltedPasswordHash(byteXorCipher, tbPassword.Text); if (LoggedInUser.PasswordHash == saltedPasswordHash) { DialogResult = DialogResult.OK; xorPwdPart1 = Byte.MaxValue; break; } xorPwdPart2++; } xorPwdPart1++; } }
public static string GetSaltedPasswordHash(ByteXorCipher byteXorCipher, string password) { var bytes = Encoding.UTF8.GetBytes(password); var encryptedBytes = byteXorCipher.Encrypt(bytes).ToArray(); var enryptedString = Encoding.UTF8.GetString(encryptedBytes); return(Hash.SHA2_Hash(enryptedString)); }
public static string GetSaltedPasswordHash(string password) { var xorPassword = new byte[2]; var random = new Random(Environment.TickCount); random.NextBytes(xorPassword); var byteXorCipher = new ByteXorCipher(xorPassword); return(GetSaltedPasswordHash(byteXorCipher, password)); }