Refactoring and password hashing
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user