added a simple password protection system

This commit is contained in:
Izaya 2017-09-07 13:12:10 +10:00
parent af2ce42583
commit 56aca17c96
4 changed files with 27 additions and 1 deletions

View File

@ -17,6 +17,7 @@ modules/lib/readline.lua
modules/lib/shutil.lua modules/lib/shutil.lua
modules/lib/sha256.lua modules/lib/sha256.lua
modules/net/net-ext.lua modules/net/net-ext.lua
modules/applications/login.lua
modules/applications/luash.lua modules/applications/luash.lua
modules/applications/genkernel.lua modules/applications/genkernel.lua
fwrap skex exec/skex2.lua fwrap skex exec/skex2.lua

9
hashpass.lua Normal file
View File

@ -0,0 +1,9 @@
require "modules/lib/sha256"
pass = io.read()
salt = ""
math.randomseed(os.time())
for i = 1, 16 do
salt = salt .. string.char(math.random(32,127))
end
print("_G.PASS_HASH = \""..sha.sha256(pass..salt).."\"")
print("_G.PASS_SALT = \""..salt.."\"")

View File

@ -0,0 +1,14 @@
function login()
if _G.PASS_HASH and _G.PASS_SALT then
io.write("\f")
io.write(_G.MOTD.."\nPassword: ")
local pt = io.read()
if pt then
if sha.sha256(pt.._G.PASS_SALT) == _G.PASS_HASH then
return true
end
end
return false
end
return true
end

View File

@ -1,6 +1,8 @@
function luash(si) function luash(si)
spawn("lua shell",function() spawn("lua shell",function()
print(MOTD) repeat
until login()
print("\f"..MOTD)
print(_VERSION) print(_VERSION)
while true do while true do
write((os.getenv("PWD") or "").."> ") write((os.getenv("PWD") or "").."> ")