-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixPasswordTool.cs
More file actions
53 lines (46 loc) · 1.81 KB
/
FixPasswordTool.cs
File metadata and controls
53 lines (46 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using ExcelDatabaseImportTool.Data.Context;
using ExcelDatabaseImportTool.Services.Database;
using ExcelDatabaseImportTool.Utilities;
using Microsoft.EntityFrameworkCore;
// Simple console tool to fix corrupted passwords in the database
Console.WriteLine("Excel Database Import Tool - Password Fix Utility");
Console.WriteLine("==================================================\n");
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
optionsBuilder.UseSqlite("Data Source=ExcelImportTool.db");
using var context = new ApplicationDbContext(optionsBuilder.Options);
var encryptionService = new EncryptionService();
var fixer = new FixCorruptedPasswords(context, encryptionService);
Console.WriteLine("Choose an option:");
Console.WriteLine("1. Clear all passwords (you'll need to re-enter them)");
Console.WriteLine("2. Try to re-encrypt passwords (if they were stored as plain text)");
Console.Write("\nEnter option (1 or 2): ");
var choice = Console.ReadLine();
try
{
if (choice == "1")
{
var count = await fixer.ClearAllPasswordsAsync();
Console.WriteLine($"\n✓ Cleared passwords for {count} configuration(s).");
Console.WriteLine("Please open the application and re-enter your passwords.");
}
else if (choice == "2")
{
var count = await fixer.FixPasswordsAsync();
Console.WriteLine($"\n✓ Fixed {count} password(s).");
if (count == 0)
{
Console.WriteLine("No passwords needed fixing, or they couldn't be fixed.");
Console.WriteLine("Consider using option 1 to clear passwords instead.");
}
}
else
{
Console.WriteLine("\nInvalid option.");
}
}
catch (Exception ex)
{
Console.WriteLine($"\n✗ Error: {ex.Message}");
}
Console.WriteLine("\nPress any key to exit...");
Console.ReadKey();