//----------------------------------------------------------------------- // // Copyright (c) aliasvault. All rights reserved. // Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information. // //----------------------------------------------------------------------- namespace AliasServerDb; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using AliasVault.Shared.Models.Enums; using Microsoft.EntityFrameworkCore; /// /// Represents the reason for an authentication failure. /// public enum AuthFailureReason { /// /// Indicates that the provided username was invalid or not found. /// InvalidUsername = 1, /// /// Indicates that the provided password was incorrect. /// InvalidPassword = 2, /// /// Indicates that the account is locked, possibly due to too many failed attempts. /// AccountLocked = 3, /// /// Indicates that the provided two-factor authentication code was invalid. /// InvalidTwoFactorCode = 4, /// /// Indicates that the provided account recovery code was invalid. /// InvalidRecoveryCode = 5, /// /// Indicates that the provided refresh token was invalid. /// InvalidRefreshToken = 6, /// /// Indicates that the account is manually blocked by an administrator. /// AccountBlocked = 7, /// /// Indicates that the failure reason was unknown. /// Unknown = 99, } /// /// Represents an authentication log in the system. /// [Index(nameof(IpAddress), Name = "IX_IpAddress")] [Index(nameof(Timestamp), Name = "IX_Timestamp")] [Index(nameof(EventType), Name = "IX_EventType")] [Index(nameof(Username), nameof(Timestamp), IsDescending = new[] { false, true }, Name = "IX_Username_Timestamp")] [Index(nameof(Username), nameof(IsSuccess), nameof(Timestamp), IsDescending = new[] { false, false, true }, Name = "IX_Username_IsSuccess_Timestamp")] public class AuthLog { /// /// Gets or sets the unique identifier for the authentication log entry. /// [Key] public int Id { get; set; } /// /// Gets or sets the date and time when the authentication event occurred. /// [Required] public DateTime Timestamp { get; set; } /// /// Gets or sets the username associated with the authentication event. /// [Required] [MaxLength(255)] public string Username { get; set; } = null!; /// /// Gets or sets the type of authentication event (e.g., Login, Logout, FailedLogin). /// [Required] public AuthEventType EventType { get; set; } /// /// Gets or sets a value indicating whether the authentication event was successful. /// This may be null for events where success is not applicable (e.g., Logout). /// public bool IsSuccess { get; set; } /// /// Gets or sets the reason for failure if the authentication event was unsuccessful. /// This is null for successful events or events where failure is not applicable. /// public AuthFailureReason? FailureReason { get; set; } /// /// Gets or sets the IP address from which the authentication event originated. /// [MaxLength(50)] public string? IpAddress { get; set; } /// /// Gets or sets the type of device used for the authentication event (e.g., Mobile, Desktop, Tablet). /// [MaxLength(100)] public string? DeviceType { get; set; } /// /// Gets or sets the operating system of the device used for the authentication event. /// [MaxLength(100)] public string? OperatingSystem { get; set; } /// /// Gets or sets the browser used for the authentication event. /// [MaxLength(100)] public string? Browser { get; set; } /// /// Gets or sets the country from which the authentication event originated. /// [MaxLength(50)] public string? Country { get; set; } /// /// Gets or sets additional information relevant to the authentication event. /// [MaxLength(255)] public string? AdditionalInfo { get; set; } /// /// Gets or sets the request path of the authentication event. /// [MaxLength(100)] public string? RequestPath { get; set; } /// /// Gets or sets a value indicating whether the authentication event is flagged as suspicious activity. /// public bool IsSuspiciousActivity { get; set; } /// /// Gets or sets the client application name and version. /// [MaxLength(100)] public string? Client { get; set; } }