mirror of
https://github.com/Ikatono/ComiServ.git
synced 2025-10-28 20:45:35 -05:00
Rearranged repo to make room for additional projects
This commit is contained in:
37
ComiServ/Entities/User.cs
Normal file
37
ComiServ/Entities/User.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace ComiServ.Entities;
|
||||
|
||||
[PrimaryKey(nameof(Id))]
|
||||
[Index(nameof(Username), IsUnique = true)]
|
||||
public class User
|
||||
{
|
||||
public const int HashLengthBytes = 512 / 8;
|
||||
public const int SaltLengthBytes = HashLengthBytes;
|
||||
public int Id { get; set; }
|
||||
[MaxLength(20)]
|
||||
public string Username { get; set; }
|
||||
[MaxLength(SaltLengthBytes)]
|
||||
public byte[] Salt { get; set; }
|
||||
[MaxLength(HashLengthBytes)]
|
||||
public byte[] HashedPassword { get; set; }
|
||||
public UserType UserType { get; set; }
|
||||
public UserTypeEnum UserTypeId { get; set; }
|
||||
[InverseProperty("User")]
|
||||
public ICollection<ComicRead> ComicsRead { get; set; } = [];
|
||||
//cryptography should probably be in a different class
|
||||
public static byte[] MakeSalt()
|
||||
{
|
||||
byte[] arr = new byte[SaltLengthBytes];
|
||||
RandomNumberGenerator.Fill(new Span<byte>(arr));
|
||||
return arr;
|
||||
}
|
||||
public static byte[] Hash(byte[] password, byte[] salt)
|
||||
{
|
||||
var salted = salt.Append((byte)':').Concat(password).ToArray();
|
||||
return SHA512.HashData(salted);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user