IW4M-Admin/SharedLibraryCore/Helpers/Hashing.cs

40 lines
992 B
C#
Raw Normal View History

2018-04-08 02:44:42 -04:00
using SimpleCrypto;
namespace SharedLibraryCore.Helpers
{
public class Hashing
{
/// <summary>
2022-01-26 11:32:16 -05:00
/// Generate password hash and salt
2018-04-08 02:44:42 -04:00
/// </summary>
/// <param name="password">plaintext password</param>
/// <param name="saltStr">salt of password</param>
2018-04-08 02:44:42 -04:00
/// <returns></returns>
public static string[] Hash(string password, string saltStr = null)
{
string hash;
string salt;
var CryptoSvc = new PBKDF2();
// generate new hash
if (saltStr == null)
{
hash = CryptoSvc.Compute(password);
salt = CryptoSvc.Salt;
2022-01-26 11:32:16 -05:00
return new[]
2018-04-08 02:44:42 -04:00
{
hash,
salt
};
}
2022-01-26 11:32:16 -05:00
hash = CryptoSvc.Compute(password, saltStr);
return new[]
2018-04-08 02:44:42 -04:00
{
2022-01-26 11:32:16 -05:00
hash,
""
};
2018-04-08 02:44:42 -04:00
}
}
}