ShoppingApp/Weifer.ShoppingApp.API/Controllers/AuthenticationController.cs
marcus 7e14d8d6ae adds working login
adds working customer creation
2024-02-25 22:59:50 +01:00

34 lines
1.1 KiB
C#

using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Text;
namespace Weifer.ShoppingApp.API.Controllers
{
public class AuthenticationController
{
public string HashPassword(string password)
{
string hashedPassword = BCrypt.Net.BCrypt.HashPassword(password);
return hashedPassword;
}
public bool VerifyPassword(string password, string hashedPassword)
{
return BCrypt.Net.BCrypt.Verify(password, hashedPassword);
}
public string GenerateJwtToken()
{
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("weifer.shoppingapp"));
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
var token = new JwtSecurityToken(
issuer: "localhost",
audience: "localhost",
expires: DateTime.Now.AddMinutes(15),
signingCredentials: credentials);
return new JwtSecurityTokenHandler().WriteToken(token);
}
}
}