Refactoring and password hashing

This commit is contained in:
kdeng00
2023-09-26 18:58:46 -04:00
parent 8f090bd2e2
commit d2c84966b9
5 changed files with 182 additions and 66 deletions
+42
View File
@@ -0,0 +1,42 @@
using System;
using System.Security.Cryptography;
using System.Text;
using TextSender_API.Models;
namespace TextSender_API.Controllers;
public class PasswordVerification
{
#region Fiends
private int _keySize = 64;
private int _iterations = 350000;
#endregion
#region Constructors
#endregion
#region Methods
public Salt CreateSalt(User user)
{
var salt = new Salt();
salt.Key = RandomNumberGenerator.GetBytes(this._keySize);
return salt;
}
public string HashPassword(User user, Salt salt)
{
var hashAlgorithm = HashAlgorithmName.SHA512;
var hash = Rfc2898DeriveBytes.Pbkdf2(
Encoding.UTF8.GetBytes(user.Password!),
salt.Key!,
this._iterations,
hashAlgorithm,
this._keySize);
return Convert.ToHexString(hash);
}
#endregion
}