To create a new hash (sha2) of a string just do this:
var hasher = new Hasher.Hasher();
var hash = hasher.getHash("abcd");
var salt = hasher.Salt;
Now it is your duty to store hash and salt in a safe place, may be in a database. Now to check wheather next time the user has entered corrected password or not just do this:
var checker = new Hasher.Hasher(storedSaltValue);
if(checker.match(enteredByUserString, storedHash))
{
//user has entered correct password
}
I mean here checker.match("abcd", hash) will return true but checker.match("pqrs", hash) will return false (any other string except "abcd")
You can download Hasher from NuGet
var hasher = new Hasher.Hasher();
var hash = hasher.getHash("abcd");
var salt = hasher.Salt;
Now it is your duty to store hash and salt in a safe place, may be in a database. Now to check wheather next time the user has entered corrected password or not just do this:
var checker = new Hasher.Hasher(storedSaltValue);
if(checker.match(enteredByUserString, storedHash))
{
//user has entered correct password
}
I mean here checker.match("abcd", hash) will return true but checker.match("pqrs", hash) will return false (any other string except "abcd")
You can download Hasher from NuGet
No comments:
Post a Comment