c# sha1 password example

System.Security.Cryptography.SHA1 hasher = System.Security.Cryptography.SHA1.Create();
string Password = "1234";
// Convert to bytes
Byte[] PasswordAsBytes = System.Text.Encoding.UTF8.GetBytes(Password);
// Hash bytes
Byte[] HashedPassword = hasher.ComputeHash(PasswordAsBytes);
Console.Write("Password: ");
// Get Input
string Input = Console.ReadLine();
// Convert to bytes
Byte[] InputAsBytes = System.Text.Encoding.UTF8.GetBytes(Input);
// Hash bytes
Byte[] HashedInput = hasher.ComputeHash(InputAsBytes);
// To compare, turn all to string
// Bytes to bytes doesn't work. I don't know why.
string HashedPasswordString = System.Text.Encoding.UTF8.GetString(HashedPassword);
string HashedInputString = System.Text.Encoding.UTF8.GetString(HashedInput);
if (HashedInputString == HashedPasswordString)
{
	Console.WriteLine("Your password matches.");
}
else
{
	Console.WriteLine("Your password doesn't match.");
}
Convert.FromBase64String("asdafaw");
// If you don't want the un-hashed string to be in the code:
HashedPasswordString = "q\u0010��О\u0006*�䣐��r�\r,\u0002";
// Just paste the hashed and converted to string version of the password to "HashedPasswordString"

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source