You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
PortfolioLink/backend/Controllers/HashPasswordController.cs

41 lines
1.2 KiB

using Microsoft.AspNetCore.Mvc;
using Hasher;
using Models;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Microsoft.IdentityModel.Tokens;
namespace backend.Controllers
{
///<summary>
/// For generating Argon2d hashes in test. Do not use in prod or with front end
///</summary>
[Route("api/pwhash")]
[ApiController]
public class PasswordHashController : ControllerBase
{
private readonly IConfiguration _config;
private readonly ILogger _logger;
public PasswordHashController(IConfiguration config, ILogger<PasswordHashController> logger)
{
_config = config;
_logger = logger;
}
///<summary>
/// Takes a plaintext password in the form {"password": "yourpasswordhere"},
/// generates an Argon2d hash for it (using random salt), and returns the hash
///</summary>
[HttpPost]
public ActionResult HashPassword([FromBody] dynamic plainTextPassword)
{
string password = (string) plainTextPassword.password;
string hashedPW = Argon2dHasher.GenerateArgon2Hash(password, null);
return Ok($"Password hash: '{hashedPW}'");
}
}
}