设置系统+新的RSOD

This commit is contained in:
2026-02-06 16:15:24 +08:00
parent 2124fea5e2
commit 8d6a43cd81
8 changed files with 337 additions and 74 deletions

View File

@@ -213,9 +213,18 @@ namespace CMLeonOS
List<string> lines = new List<string>();
foreach (User user in users)
{
// 使用SHA256加密密码
string hashedPassword = HashPasswordSha256(user.Password);
string line = $"{user.Username}|{hashedPassword}|{(user.IsAdmin ? "admin" : "user")}|{user.Hostname}";
string passwordToSave;
if (IsPasswordAlreadyHashed(user.Password))
{
passwordToSave = user.Password;
}
else
{
passwordToSave = HashPasswordSha256(user.Password);
}
string line = $"{user.Username}|{passwordToSave}|{(user.IsAdmin ? "admin" : "user")}|{user.Hostname}";
lines.Add(line);
}
File.WriteAllLines(userFilePath, lines.ToArray());
@@ -226,6 +235,31 @@ namespace CMLeonOS
}
}
private bool IsPasswordAlreadyHashed(string password)
{
if (string.IsNullOrWhiteSpace(password))
{
return false;
}
string trimmedPassword = password.Trim();
if (trimmedPassword.Length < 32)
{
return false;
}
foreach (char c in trimmedPassword)
{
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '+' || c == '/' || c == '='))
{
return false;
}
}
return true;
}
public bool HasUsers
{
get { return users.Count > 0; }