| | | 1 | | using System.ComponentModel.DataAnnotations; |
| | | 2 | | using ArturRios.Data.Relational.Core.Entities; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Heimdall.Domain.Entities; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// A self-registration (UC-47) waiting for its address to be confirmed. Not a person: nothing can |
| | | 8 | | /// sign in with it, which is what keeps register-then-sign-in from revealing whether an address is |
| | | 9 | | /// taken. Confirming it through the emailed link (UC-14) creates the verified <c>User</c> and |
| | | 10 | | /// removes it; an unconfirmed one expires and is purged with the other single-use tokens (NFR-19). |
| | | 11 | | /// </summary> |
| | | 12 | | public class PendingRegistration : Entity<long> |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// The confirmation-guess budget (FR-SR-09): the login lockout threshold, so a leaked link admits |
| | | 16 | | /// no more guesses at the sign-up password than the account itself would. Spent by |
| | | 17 | | /// <c>PendingRegistrationConfirmer</c>; what is left is reported by the UC-49 listing. |
| | | 18 | | /// </summary> |
| | | 19 | | public const int MaxConfirmationGuesses = 10; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// The live registrations one address may have in one scope at a time (FR-SR-13). Each is a |
| | | 23 | | /// confirmation mail to the address, so this bounds the mail registering can send it: a request |
| | | 24 | | /// beyond it creates and mails nothing, and answers exactly as any other does (AF-47b). |
| | | 25 | | /// </summary> |
| | | 26 | | public const int MaxLivePerAddress = 3; |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// The administrative reference (UC-49, UC-50): how a scope's owners name this registration to |
| | | 30 | | /// discard it. Random, so it discloses nothing about the registrant or how many registrations |
| | | 31 | | /// exist. The registrant never sees it; their reference is still the mailed token. |
| | | 32 | | /// </summary> |
| | 228 | 33 | | public Guid PublicId { get; set; } = Guid.NewGuid(); |
| | | 34 | | |
| | | 35 | | /// <summary>Foreign key to the scope registered into (internal Id).</summary> |
| | 168 | 36 | | public long ScopeId { get; set; } |
| | | 37 | | |
| | | 38 | | [MaxLength(200)] |
| | 288 | 39 | | public string Name { get; set; } = string.Empty; |
| | | 40 | | |
| | 318 | 41 | | public string Email { get; set; } = string.Empty; |
| | | 42 | | |
| | | 43 | | /// <summary>The password hash computed on the request path; the plaintext was never stored.</summary> |
| | 315 | 44 | | public byte[] PasswordHash { get; set; } = []; |
| | | 45 | | |
| | 315 | 46 | | public byte[] Salt { get; set; } = []; |
| | | 47 | | |
| | | 48 | | /// <summary>SHA-256 of the mailed token, as lowercase hex, through <c>SingleUseTokenHash</c>.</summary> |
| | | 49 | | [MaxLength(64)] |
| | 310 | 50 | | public string TokenHash { get; set; } = string.Empty; |
| | | 51 | | |
| | 226 | 52 | | public DateTime ExpiresAt { get; set; } |
| | | 53 | | |
| | 150 | 54 | | public DateTime CreatedAt { get; set; } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Wrong confirmation passwords presented with this registration's token. The row is discarded when |
| | | 58 | | /// the count reaches the login lockout threshold, so a leaked link cannot be used to guess the |
| | | 59 | | /// sign-up password without limit. |
| | | 60 | | /// </summary> |
| | 242 | 61 | | public int FailedAttempts { get; set; } |
| | | 62 | | |
| | 62 | 63 | | public Scope Scope { get; set; } = null!; |
| | | 64 | | } |