diff --git a/LANCommander/Controllers/Api/AuthController.cs b/LANCommander/Controllers/Api/AuthController.cs index a180f0d..64edd57 100644 --- a/LANCommander/Controllers/Api/AuthController.cs +++ b/LANCommander/Controllers/Api/AuthController.cs @@ -173,7 +173,7 @@ namespace LANCommander.Controllers.Api var refreshToken = GenerateRefreshToken(); user.RefreshToken = refreshToken; - user.RefreshTokenExpiration = DateTime.Now.AddDays(Settings.TokenLifetime); + user.RefreshTokenExpiration = DateTime.Now.AddDays(Settings.Authentication.TokenLifetime); await UserManager.UpdateAsync(user); @@ -190,10 +190,10 @@ namespace LANCommander.Controllers.Api private JwtSecurityToken GetToken(List authClaims) { - var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Settings.TokenSecret)); + var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Settings.Authentication.TokenSecret)); var token = new JwtSecurityToken( - expires: DateTime.Now.AddDays(Settings.TokenLifetime), + expires: DateTime.Now.AddDays(Settings.Authentication.TokenLifetime), claims: authClaims, signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256) ); @@ -220,7 +220,7 @@ namespace LANCommander.Controllers.Api ValidateAudience = false, ValidateIssuer = false, ValidateIssuerSigningKey = true, - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Settings.TokenSecret)), + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Settings.Authentication.TokenSecret)), ValidateLifetime = false }; diff --git a/LANCommander/Models/Settings.cs b/LANCommander/Models/Settings.cs index c37efc0..4146505 100644 --- a/LANCommander/Models/Settings.cs +++ b/LANCommander/Models/Settings.cs @@ -2,12 +2,23 @@ { public class LANCommanderSettings { - public int Port { get; set; } - public bool Beacon { get; set; } - public string TokenSecret { get; set; } - public int TokenLifetime { get; set; } - public string DatabaseConnectionString { get; set; } - public string IGDBClientId { get; set; } - public string IGDBClientSecret { get; set; } + public int Port { get; set; } = 1337; + public bool Beacon { get; set; } = true; + public string DatabaseConnectionString { get; set; } = ""; + public string IGDBClientId { get; set; } = ""; + public string IGDBClientSecret { get; set; } = ""; + + public LANCommanderAuthenticationSettings Authentication { get; set; } = new LANCommanderAuthenticationSettings(); + } + + public class LANCommanderAuthenticationSettings + { + public string TokenSecret { get; set; } = ""; + public int TokenLifetime { get; set; } = 30; + public bool PasswordRequireNonAlphanumeric { get; set; } + public bool PasswordRequireLowercase { get; set; } + public bool PasswordRequireUppercase { get; set; } + public bool PasswordRequireDigit { get; set; } + public int PasswordRequiredLength { get; set; } = 8; } } diff --git a/LANCommander/Pages/Settings/Authentication.razor b/LANCommander/Pages/Settings/Authentication.razor new file mode 100644 index 0000000..921b2f5 --- /dev/null +++ b/LANCommander/Pages/Settings/Authentication.razor @@ -0,0 +1,67 @@ +@page "/Settings/Authentication" +@using LANCommander.Models; +@layout SettingsLayout +@inject SettingService SettingService +@inject IMessageService MessageService + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +@code { + LANCommanderSettings Settings; + + protected override async Task OnInitializedAsync() + { + Settings = SettingService.GetSettings(); + } + + private string FormatTokenLifetime(int value) + { + return value.ToString() + " days"; + } + + private void Save() + { + try + { + SettingService.SaveSettings(Settings); + MessageService.Success("Settings saved!"); + } + catch + { + MessageService.Error("An unknown error occurred."); + } + } +} diff --git a/LANCommander/Pages/Settings/SettingsLayout.razor b/LANCommander/Pages/Settings/SettingsLayout.razor index f30df99..cb5a856 100644 --- a/LANCommander/Pages/Settings/SettingsLayout.razor +++ b/LANCommander/Pages/Settings/SettingsLayout.razor @@ -6,6 +6,7 @@ General Users + Authentication diff --git a/LANCommander/Program.cs b/LANCommander/Program.cs index e40bfe4..7deeec8 100644 --- a/LANCommander/Program.cs +++ b/LANCommander/Program.cs @@ -46,8 +46,13 @@ builder.Services.AddDatabaseDeveloperPageExceptionFilter(); builder.Services.AddDefaultIdentity((IdentityOptions options) => { options.SignIn.RequireConfirmedAccount = false; - options.Password.RequireNonAlphanumeric = false; options.SignIn.RequireConfirmedEmail = false; + + options.Password.RequireNonAlphanumeric = settings.Authentication.PasswordRequireNonAlphanumeric; + options.Password.RequireLowercase = settings.Authentication.PasswordRequireLowercase; + options.Password.RequireUppercase = settings.Authentication.PasswordRequireUppercase; + options.Password.RequireDigit = settings.Authentication.PasswordRequireDigit; + options.Password.RequiredLength = settings.Authentication.PasswordRequiredLength; }) .AddRoles() .AddEntityFrameworkStores() @@ -69,7 +74,7 @@ builder.Services.AddAuthentication(options => ValidateAudience = false, // ValidAudience = configuration["JWT:ValidAudience"], // ValidIssuer = configuration["JWT:ValidIssuer"], - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settings.TokenSecret)) + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settings.Authentication.TokenSecret)) }; });