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.
3.01-QCM_MuscuMaths/Blazor/Blazor/Models/PlayerModel.cs

38 lines
1.2 KiB

using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Text;
namespace Blazor.Models;
public class PlayerModel
{
public int Id { get; set; }
[Required(ErrorMessage = "Nickname is required")]
[StringLength(50, ErrorMessage = "Nickname is too long.")]
public string Nickname { get; set; }
[Required(ErrorMessage = "Password is required")]
[RegularExpression(@"^[^\s]+$", ErrorMessage = "Le champ ne doit pas contenir d'espaces.")]
[StringLength(255, ErrorMessage = "{0} length must be between {2} and {1}.", MinimumLength = 6)]
public string HashedPassword { get; set; }
public void HashPassword(string password)
{
using (MD5 md5 = MD5.Create())
{
byte[] inputBytes = Encoding.UTF8.GetBytes(password);
byte[] hashBytes = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
}
HashedPassword = sb.ToString();
}
}
}