Rearranged repo to make room for additional projects

This commit is contained in:
Cameron
2024-09-07 20:31:54 -05:00
parent 7479dbf8f8
commit 0082a6f219
50 changed files with 92 additions and 1 deletions

37
ComiServ/Entities/User.cs Normal file
View 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);
}
}