feat(安全): 添加管理员账户创建和登录验证功能

在安装过程中添加管理员账户创建流程,并在系统启动时进行登录验证
更新系统版本号为 LeonOS Alpha 1.1
This commit is contained in:
2025-08-31 21:26:08 +08:00
parent 60f00f6dcb
commit d0b30feca9
2 changed files with 48 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
_G._HOST = _G._HOST .. " (LeonOS 1.6.0)" _G._HOST = _G._HOST .. " (LeonOS Alpha 1.1)"
local fs = rawget(_G, "fs") local fs = rawget(_G, "fs")
@@ -184,6 +184,31 @@ end
expect = require("cc.expect").expect expect = require("cc.expect").expect
-- Admin login verification
local tu = require("rom.apis.textutils")
local admin_username = settings.get("LeonOS.users.admin.username")
local admin_password = settings.get("LeonOS.users.admin.password")
if admin_username then
term.clear()
tu.coloredPrint(colors.yellow, "LeonOS Login\n=======================")
tu.coloredPrint("Username: ", colors.lightBlue, admin_username)
if admin_password then
tu.coloredPrint("Password: ")
local input_password = read(nil, {}, nil, true) -- Use password mode
while input_password ~= admin_password do
tu.coloredPrint(colors.red, "Incorrect password!\n")
tu.coloredPrint("Password: ")
input_password = read(nil, {}, nil, true)
end
else
tu.coloredPrint(colors.green, "No password set. Press Enter to continue.")
read()
end
end
local thread = require("rc.thread") local thread = require("rc.thread")
thread.start() thread.start()

View File

@@ -86,6 +86,28 @@ if #ROM_DIR == 0 then ROM_DIR = DEFAULT_ROM_DIR end
ROM_DIR = "/"..shell.resolve(ROM_DIR) ROM_DIR = "/"..shell.resolve(ROM_DIR)
settings.set("LeonOS.rom_dir", ROM_DIR) settings.set("LeonOS.rom_dir", ROM_DIR)
-- Create admin user
print("")
tu.coloredPrint(colors.yellow, "Create Administrator Account\n=======================")
tu.coloredPrint("Enter admin username: ")
local admin_username = read()
while #admin_username == 0 do
tu.coloredPrint(colors.red, "Username cannot be empty!\n")
tu.coloredPrint("Enter admin username: ")
admin_username = read()
end
tu.coloredPrint("Enter admin password (leave empty for no password): ")
local admin_password = read(nil, {}, nil, true) -- Use password mode
-- Save user info
settings.set("LeonOS.users.admin.username", admin_username)
if #admin_password > 0 then
settings.set("LeonOS.users.admin.password", admin_password)
else
settings.set("LeonOS.users.admin.password", nil)
end
settings.save() settings.save()
tu.coloredPrint(colors.white, "Installing LeonOS to ", colors.lightBlue, tu.coloredPrint(colors.white, "Installing LeonOS to ", colors.lightBlue,