Dreamine.Web 1.0.0.0
WPF와 Blazor를 한 코드 흐름으로 연결하고 반복적인 MVVM 코드를 줄이는 오픈소스 FullKit 공식 웹 애플리케이션입니다.
로딩중...
검색중...
일치하는것 없음
AdminAuthService.cs
이 파일의 문서화 페이지로 가기
1using System.IO;
2using System.Text.Json;
3using Dreamine.Identity;
5
7
16public class AdminAuthService
17{
26 private readonly string _filePath;
35 private readonly string _fallbackPassword;
44 private string? _overridePassword;
45
54 private static readonly JsonSerializerOptions _json = new() { WriteIndented = true };
55
73 {
75 _filePath = Path.Combine(opts.ResolvedDataPath, "admin_auth.json");
76
77 if (File.Exists(_filePath))
78 {
79 try
80 {
81 var doc = JsonSerializer.Deserialize<AdminAuthData>(File.ReadAllText(_filePath));
82 _overridePassword = doc?.Password;
83 }
84 catch { }
85 }
86 }
87
112 public bool Verify(string password)
113 {
114 var storedPassword = _overridePassword ?? _fallbackPassword;
115 var verification = DreaminePasswordHasher.VerifyPassword(password, storedPassword, out var upgradedHash);
116 if (verification is PasswordHashVerificationResult.Failed)
117 {
118 return false;
119 }
120
121 if (_overridePassword is not null &&
122 verification is PasswordHashVerificationResult.SuccessRehashNeeded &&
123 upgradedHash is not null)
124 {
125 _overridePassword = upgradedHash;
126 WriteOverridePassword(upgradedHash);
127 }
128
129 return true;
130 }
131
156 public async Task ChangePasswordAsync(string newPassword)
157 {
158 _overridePassword = DreaminePasswordHasher.HashPassword(newPassword);
159 Directory.CreateDirectory(Path.GetDirectoryName(_filePath)!);
160 await File.WriteAllTextAsync(_filePath,
161 JsonSerializer.Serialize(new AdminAuthData { Password = _overridePassword }, _json));
162 }
163
180 private void WriteOverridePassword(string passwordHash)
181 {
182 Directory.CreateDirectory(Path.GetDirectoryName(_filePath)!);
183 File.WriteAllText(_filePath, JsonSerializer.Serialize(new AdminAuthData { Password = passwordHash }, _json));
184 }
185
194 private sealed class AdminAuthData
195 {
204 public string Password { get; set; } = string.Empty;
205 }
206}
static readonly JsonSerializerOptions _json
void WriteOverridePassword(string passwordHash)
async Task ChangePasswordAsync(string newPassword)