-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthenticator.cs
More file actions
31 lines (28 loc) · 937 Bytes
/
Authenticator.cs
File metadata and controls
31 lines (28 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Security.Cryptography;
using System.Text;
namespace PasswordHashing
{
public static class Authenticator
{
public static string GenerateSalt(int size)
{
var rng = new RNGCryptoServiceProvider();
byte[] buff = new byte[size];
rng.GetBytes(buff);
return Convert.ToBase64String(buff);
}
public static string GenerateHash(string input, string salt)
{
var bytes = Encoding.UTF8.GetBytes(input + salt);
var sHA256ManagedString = new SHA256Managed();
var hash = sHA256ManagedString.ComputeHash(bytes);
return Convert.ToBase64String(hash);
}
public static bool Authenticate(string password, string hashedInput, string salt)
{
var newHash = GenerateHash(password, salt);
return newHash.Equals(hashedInput);
}
}
}