Skip to content

Commit 2fe77f7

Browse files
feat(security): add database password encryption support
- Store database password encrypted in DatabaseSettings section - Update DependencyInjection to decrypt password at runtime - Connection string uses {ENCRYPTED} placeholder replaced at startup - Update database server to 10.10.30.7 (PrinterPix_BO_Live) Security improvement: Database password is now stored encrypted in configuration files instead of plain text. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3203cae commit 2fe77f7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/OrderMonitor.Api/appsettings.Development.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"ConnectionStrings": {
3-
"BackofficeDb": "Server=localhost;Database=Backoffice;Trusted_Connection=True;TrustServerCertificate=True;ApplicationIntent=ReadOnly;"
3+
"BackofficeDb": "Server=10.10.30.7,1433;Database=PrinterPix_BO_Live;User Id=db_PIX_BackOffice_Live;Password={ENCRYPTED};TrustServerCertificate=True;ApplicationIntent=ReadOnly;"
4+
},
5+
6+
"DatabaseSettings": {
7+
"EncryptedPassword": "BtB8i+odFInds4FDG1smnzWrLl2E5KwJsQLeoW0HzIc="
48
},
59

610
"Scanner": {

src/OrderMonitor.Infrastructure/DependencyInjection.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using OrderMonitor.Core.Interfaces;
55
using OrderMonitor.Core.Services;
66
using OrderMonitor.Infrastructure.Data;
7+
using OrderMonitor.Infrastructure.Security;
78
using OrderMonitor.Infrastructure.Services;
89

910
namespace OrderMonitor.Infrastructure;
@@ -24,6 +25,17 @@ public static IServiceCollection AddInfrastructure(
2425
var connectionString = configuration.GetConnectionString("BackofficeDb")
2526
?? throw new InvalidOperationException("BackofficeDb connection string is not configured.");
2627

28+
// Check if password is encrypted (contains placeholder)
29+
if (connectionString.Contains("{ENCRYPTED}"))
30+
{
31+
var encryptedPassword = configuration["DatabaseSettings:EncryptedPassword"];
32+
if (!string.IsNullOrEmpty(encryptedPassword))
33+
{
34+
var decryptedPassword = PasswordEncryptor.Decrypt(encryptedPassword);
35+
connectionString = connectionString.Replace("{ENCRYPTED}", decryptedPassword);
36+
}
37+
}
38+
2739
services.AddSingleton<IDbConnectionFactory>(sp => new SqlConnectionFactory(connectionString));
2840

2941
// Register repositories

0 commit comments

Comments
 (0)