mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-04-21 10:53:59 +00:00
修改登陆页面
This commit is contained in:
@@ -1 +1 @@
|
||||
2026-03-21 23:18:24
|
||||
2026-03-22 13:55:03
|
||||
@@ -1 +1 @@
|
||||
ca30113
|
||||
126017b
|
||||
@@ -30,8 +30,8 @@ namespace CMLeonOS.Gui.ShellComponents
|
||||
|
||||
AppWindow window;
|
||||
|
||||
TextBox usernameBox;
|
||||
|
||||
Table userTable;
|
||||
|
||||
TextBox passwordBox;
|
||||
|
||||
WindowManager wm = ProcessManager.GetProcess<WindowManager>();
|
||||
@@ -46,7 +46,7 @@ namespace CMLeonOS.Gui.ShellComponents
|
||||
}
|
||||
|
||||
private const int width = 352;
|
||||
private const int height = 128;
|
||||
private const int height = 200;
|
||||
private const int padding = 12;
|
||||
|
||||
private double shakiness = 0;
|
||||
@@ -57,7 +57,7 @@ namespace CMLeonOS.Gui.ShellComponents
|
||||
|
||||
window.DrawImageAlpha(Images.Icon_Key, padding, padding);
|
||||
|
||||
window.DrawString("Enter your username and password,\nthen press Enter to log on", Color.Black, (int)(padding + Images.Icon_Key.Width + padding), padding);
|
||||
window.DrawString("Select a user and enter password,\nthen press Enter to log on", Color.Black, (int)(padding + Images.Icon_Key.Width + padding), padding);
|
||||
}
|
||||
|
||||
private void ShowError(string text)
|
||||
@@ -73,17 +73,21 @@ namespace CMLeonOS.Gui.ShellComponents
|
||||
|
||||
private void LogOn()
|
||||
{
|
||||
if (usernameBox.Text.Trim() == string.Empty || passwordBox.Text.Trim() == string.Empty)
|
||||
if (userTable.SelectedCellIndex < 0 || passwordBox.Text.Trim() == string.Empty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string username = usernameBox.Text.Trim();
|
||||
string password = passwordBox.Text.Trim();
|
||||
|
||||
Logger.Logger.Instance.Info("Lock", $"Attempting login for user: {username}");
|
||||
if (userTable.SelectedCellIndex >= UserSystem.GetUsers().Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var users = UserSystem.GetUsers();
|
||||
User selectedUser = users[userTable.SelectedCellIndex];
|
||||
string password = passwordBox.Text.Trim();
|
||||
|
||||
Logger.Logger.Instance.Info("Lock", $"Attempting login for user: {selectedUser.Username}");
|
||||
Logger.Logger.Instance.Info("Lock", $"UserSystem.GetUsers() returned: {(users == null ? "null" : users.Count.ToString())}");
|
||||
|
||||
if (users == null || users.Count == 0)
|
||||
@@ -94,37 +98,17 @@ namespace CMLeonOS.Gui.ShellComponents
|
||||
return;
|
||||
}
|
||||
|
||||
User foundUser = null;
|
||||
foreach (User user in users)
|
||||
{
|
||||
Logger.Logger.Instance.Info("Lock", $"Checking user: {user.Username} (lower: {user.Username.ToLower()})");
|
||||
if (user.Username.ToLower() == username.ToLower())
|
||||
{
|
||||
foundUser = user;
|
||||
Logger.Logger.Instance.Info("Lock", $"User matched: {foundUser.Username}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundUser == null)
|
||||
{
|
||||
Logger.Logger.Instance.Warning("Lock", $"User not found: {username}");
|
||||
Shake();
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Logger.Instance.Info("Lock", $"User found: {foundUser.Username}, Admin: {foundUser.Admin}");
|
||||
|
||||
Logger.Logger.Instance.Info("Lock", $"User found: {selectedUser.Username}, Admin: {selectedUser.Admin}");
|
||||
string hashedInputPassword = UserSystem.HashPasswordSha256(password);
|
||||
|
||||
if (foundUser.Password != hashedInputPassword)
|
||||
if (selectedUser.Password != hashedInputPassword)
|
||||
{
|
||||
Logger.Logger.Instance.Warning("Lock", $"Authentication failed for user: {foundUser.Username}");
|
||||
Logger.Logger.Instance.Warning("Lock", $"Authentication failed for user: {selectedUser.Username}");
|
||||
passwordBox.Text = string.Empty;
|
||||
|
||||
if (foundUser.LockedOut)
|
||||
if (selectedUser.LockedOut)
|
||||
{
|
||||
TimeSpan remaining = foundUser.LockoutEnd - DateTime.Now;
|
||||
TimeSpan remaining = selectedUser.LockoutEnd - DateTime.Now;
|
||||
if (remaining.Minutes > 0)
|
||||
{
|
||||
ShowError($"Try again in {remaining.Minutes}m, {remaining.Seconds}s.");
|
||||
@@ -141,15 +125,14 @@ namespace CMLeonOS.Gui.ShellComponents
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Logger.Instance.Info("Lock", $"Authentication successful for user: {foundUser.Username}");
|
||||
|
||||
Logger.Logger.Instance.Info("Lock", $"Authentication successful for user: {selectedUser.Username}");
|
||||
TryStop();
|
||||
UserSystem.SetCurrentLoggedInUser(foundUser);
|
||||
UserSystem.SetCurrentLoggedInUser(selectedUser);
|
||||
ProcessManager.AddProcess(wm, new ShellComponents.Taskbar()).Start();
|
||||
ProcessManager.AddProcess(wm, new ShellComponents.Dock.Dock()).Start();
|
||||
soundService.PlaySystemSound(Sound.SystemSound.Login);
|
||||
|
||||
Logger.Logger.Instance.Info("Lock", $"{foundUser.Username} logged on to the GUI.");
|
||||
Logger.Logger.Instance.Info("Lock", $"{selectedUser.Username} logged on to GUI.");
|
||||
}
|
||||
|
||||
private void LogOnClick(int x, int y)
|
||||
@@ -182,13 +165,32 @@ namespace CMLeonOS.Gui.ShellComponents
|
||||
RenderBackground();
|
||||
|
||||
int boxesStartY = (int)(padding + Images.Icon_Key.Height + padding);
|
||||
|
||||
userTable = new Table(window, padding, boxesStartY, 160, 80);
|
||||
userTable.CellHeight = 25;
|
||||
userTable.Background = Color.White;
|
||||
userTable.Foreground = Color.Black;
|
||||
userTable.Border = Color.Gray;
|
||||
userTable.SelectedBackground = Color.FromArgb(221, 246, 255);
|
||||
userTable.SelectedForeground = Color.Black;
|
||||
userTable.SelectedBorder = Color.FromArgb(126, 205, 234);
|
||||
userTable.AllowSelection = true;
|
||||
userTable.AllowDeselection = false;
|
||||
|
||||
foreach (var user in users)
|
||||
{
|
||||
var cell = new TableCell(user.Username);
|
||||
userTable.Cells.Add(cell);
|
||||
}
|
||||
|
||||
if (userTable.Cells.Count > 0)
|
||||
{
|
||||
userTable.SelectedCellIndex = 0;
|
||||
}
|
||||
|
||||
wm.AddWindow(userTable);
|
||||
|
||||
usernameBox = new TextBox(window, padding, boxesStartY, 160, 20);
|
||||
usernameBox.PlaceholderText = "Username";
|
||||
usernameBox.Submitted = LogOn;
|
||||
wm.AddWindow(usernameBox);
|
||||
|
||||
passwordBox = new TextBox(window, padding, boxesStartY + padding + 20, 160, 20);
|
||||
passwordBox = new TextBox(window, padding, boxesStartY + 90, 160, 20);
|
||||
passwordBox.Shield = true;
|
||||
passwordBox.PlaceholderText = "Password";
|
||||
passwordBox.Submitted = LogOn;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -648,52 +649,52 @@ namespace CMLeonOS
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.Clear();
|
||||
|
||||
var loginBox = new CMLeonOS.UI.Window(new CMLeonOS.UI.Rect(15, 8, 50, 10), "Login", () => { }, true);
|
||||
var loginBox = new CMLeonOS.UI.Window(new CMLeonOS.UI.Rect(15, 8, 50, 15), "Login", () => { }, true);
|
||||
loginBox.Render();
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(17, 10);
|
||||
global::System.Console.Write("Username: ");
|
||||
string username = global::System.Console.ReadLine();
|
||||
global::System.Console.Write("Select User:");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(17, 24);
|
||||
global::System.Console.Write("Username cannot be empty. ");
|
||||
global::System.Threading.Thread.Sleep(1000);
|
||||
return false;
|
||||
}
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(17, 11);
|
||||
global::System.Console.Write("Password: ");
|
||||
string password = ReadPassword();
|
||||
|
||||
User foundUser = null;
|
||||
var userMenu = new CMLeonOS.UI.Menu(new CMLeonOS.UI.Rect(17, 11, 46, 8));
|
||||
foreach (User user in users)
|
||||
{
|
||||
if (user.Username.ToLower() == username.ToLower())
|
||||
userMenu.Items.Add(new CMLeonOS.UI.MenuItem(user.Username));
|
||||
}
|
||||
userMenu.Render();
|
||||
|
||||
User selectedUser = null;
|
||||
while (selectedUser == null)
|
||||
{
|
||||
var key = global::System.Console.ReadKey(true);
|
||||
|
||||
if (key.Key == global::System.ConsoleKey.Enter)
|
||||
{
|
||||
foundUser = user;
|
||||
break;
|
||||
if (userMenu.SelectedIndex >= 0 && userMenu.SelectedIndex < users.Count)
|
||||
{
|
||||
selectedUser = users[userMenu.SelectedIndex];
|
||||
}
|
||||
}
|
||||
else if (key.Key == global::System.ConsoleKey.Escape)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (userMenu.HandleKey(key))
|
||||
{
|
||||
userMenu.Render();
|
||||
}
|
||||
}
|
||||
|
||||
if (foundUser == null)
|
||||
{
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(17, 24);
|
||||
global::System.Console.Write("User not found. ");
|
||||
global::System.Threading.Thread.Sleep(1000);
|
||||
return false;
|
||||
}
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(17, 20);
|
||||
global::System.Console.Write("Password: ");
|
||||
string password = ReadPassword();
|
||||
|
||||
string hashedInputPassword = HashPasswordSha256(password);
|
||||
|
||||
if (foundUser.Password != hashedInputPassword)
|
||||
if (selectedUser.Password != hashedInputPassword)
|
||||
{
|
||||
string usernameLower = username.ToLower();
|
||||
string usernameLower = selectedUser.Username.ToLower();
|
||||
|
||||
if (!loginAttempts.ContainsKey(usernameLower))
|
||||
{
|
||||
@@ -722,20 +723,19 @@ namespace CMLeonOS
|
||||
return false;
|
||||
}
|
||||
|
||||
loginAttempts.Remove(username.ToLower());
|
||||
loginAttempts.Remove(selectedUser.Username.ToLower());
|
||||
|
||||
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Green, global::System.ConsoleColor.Black);
|
||||
global::System.Console.SetCursorPosition(17, 24);
|
||||
global::System.Console.Write("Login successful! ");
|
||||
// global::System.Console.WriteLine("Please wait... ");
|
||||
global::System.Threading.Thread.Sleep(1500);
|
||||
global::System.Console.ResetColor();
|
||||
global::System.Console.Clear();
|
||||
|
||||
global::System.Console.Beep();
|
||||
|
||||
currentLoggedInUser = foundUser;
|
||||
CreateUserFolder(foundUser.Username);
|
||||
currentLoggedInUser = selectedUser;
|
||||
CreateUserFolder(selectedUser.Username);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user