Skip to content

Commit a8a9c8c

Browse files
committed
- admin password length is in settings now
1 parent 35881f0 commit a8a9c8c

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

Botticelli.Server.Back/Controllers/UserController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using Botticelli.Server.Back.Services.Auth;
2+
using Botticelli.Server.Back.Settings;
23
using Botticelli.Server.Data.Entities.Auth;
34
using Botticelli.Shared.Utils;
45
using MapsterMapper;
56
using Microsoft.AspNetCore.Authorization;
67
using Microsoft.AspNetCore.Mvc;
8+
using Microsoft.Extensions.Options;
79
using PasswordGenerator;
810

911
namespace Botticelli.Server.Back.Controllers;
@@ -14,13 +16,14 @@ namespace Botticelli.Server.Back.Controllers;
1416
[ApiController]
1517
[Authorize(AuthenticationSchemes = "Bearer")]
1618
[Route("/v1/user")]
17-
public class UserController(IUserService userService, IMapper mapper, IPasswordSender passwordSender) : Controller
19+
public class UserController(IUserService userService, IMapper mapper, IPasswordSender passwordSender, IOptionsMonitor<ServerSettings> settings) : Controller
1820
{
1921
private readonly IPassword _password = new Password(true,
2022
true,
2123
true,
2224
false,
23-
12);
25+
Random.Shared.Next(settings.CurrentValue.PasswordMinLength,
26+
settings.CurrentValue.PasswordMaxLength));
2427

2528
/// <summary>
2629
/// Does system contain any users?

Botticelli.Server.Back/Services/Auth/AdminAuthService.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
using System.IdentityModel.Tokens.Jwt;
22
using System.Security.Claims;
33
using System.Text;
4-
using Botticelli.Server.Back.Settings;
54
using Botticelli.Server.Data;
65
using Botticelli.Server.Data.Entities.Auth;
76
using Botticelli.Server.Data.Exceptions;
87
using Botticelli.Server.Models.Responses;
98
using Botticelli.Shared.Utils;
109
using Microsoft.AspNetCore.Identity;
1110
using Microsoft.EntityFrameworkCore;
12-
using Microsoft.Extensions.Options;
1311
using Microsoft.IdentityModel.Tokens;
1412

1513
namespace Botticelli.Server.Back.Services.Auth;
@@ -27,8 +25,7 @@ public class AdminAuthService : IAdminAuthService
2725
public AdminAuthService(IConfiguration config,
2826
IHttpContextAccessor httpContextAccessor,
2927
ServerDataContext context,
30-
ILogger<AdminAuthService> logger,
31-
IOptionsMonitor<ServerSettings> settings)
28+
ILogger<AdminAuthService> logger)
3229
{
3330
_config = config;
3431
_httpContextAccessor = httpContextAccessor;

Botticelli.Server.Back/Settings/ServerSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public class ServerSettings
1818
public string? AnalyticsUrl { get; set; }
1919
public required string SecureStorageConnection { get; set; }
2020
public bool UseSsl { get; set; }
21+
public int PasswordMinLength { get; set; } = 8;
22+
public int PasswordMaxLength { get; set; } = 12;
2123
}

Botticelli.Server.Back/appsettings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
},
4747
"serverEmail": "",
4848
"serverUrl": "",
49-
"analyticsUrl": ""
49+
"analyticsUrl": "",
50+
"PasswordMinLength": 8,
51+
"PasswordMaxLength": 12
5052
}
5153
}

0 commit comments

Comments
 (0)