Created
April 19, 2017 09:55
-
-
Save mikasjp/29a310dc29f3d39af213297e0f7b6dae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Security.Cryptography; | |
using System.Text; | |
public class PasswordVerificator | |
{ | |
public static void Main() | |
{ | |
string AuthenticationResult = AuthenticateUser("admin", "supersecretpassword","mysalt1f$gO3123qs")?"User authenticated!":"Access denied!"; | |
Console.WriteLine(AuthenticationResult); | |
} | |
public static string HexStringFromBytes(byte[] bytes) | |
{ | |
var sb = new StringBuilder(); | |
foreach (byte b in bytes) | |
{ | |
var hex = b.ToString("x2"); | |
sb.Append(hex); | |
} | |
return sb.ToString(); | |
} | |
public static string SHA1Hash(string s) | |
{ | |
byte[] bytes = Encoding.UTF8.GetBytes(s); | |
var sha1 = SHA1.Create(); | |
byte[] hashBytes = sha1.ComputeHash(bytes); | |
return HexStringFromBytes(hashBytes); | |
} | |
public static bool AuthenticateUser(string user, string password, string salt) | |
{ | |
return (user=="admin" && SHA1Hash(password+salt)=="4985e24b60638acf2416996093cbd2c6ef111bf3"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment