Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is a VERY simple login script, slightly more complex than hardcoded login scripts although
- --It will read a list of users from a file where a serialized list of users is stored. Before copying this
- --to your startup script, please do create a users file and verify it functions as you wish.
- local users = {}
- term.clear()
- term.setTextColor(colors.red)
- print("MTech Launch System 1.0")
- term.setTextColor(colors.white)
- print("")
- local usfile = "users"
- if not fs.exists(usfile)then
- term.setTextColor(colors.red)
- print("Core file 'users.txt' not found!")
- term.setTextColor(colors.white)
- print("")
- sleep(1)
- os.reboot()
- else
- local file = io.open("users", "r")
- local data = textutils.unserialize(file:read("*a"))
- file:close()
- if data == nil then
- term.setTextColor(colors.red)
- print("User entry data file is empty!")
- term.setTextColor(colors.white)
- print("")
- sleep(1)
- os.reboot()
- else
- users = data.users
- end
- end
- local function CheckUSR(name)
- if name == nil then return false end
- for k, v in pairs(users)do
- if(name == k)then return true else return false end
- end
- end
- local function CheckPassword(name, pass)
- if name == nil then return false end
- if pass == nil then return false end
- for k, v in pairs(users)do
- if(k == name)then
- if(pass == v)then
- return true
- else
- return false
- end
- end
- end
- return false
- end
- local function SetUp()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.red)
- textutils.slowPrint("MTech Mainframe Controller")
- term.setTextColor(colors.white)
- print("")
- if(fs.exists("init"))then
- dofile("init")
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.red)
- print("Login Area")
- term.setTextColor(colors.white)
- print("")
- print("Username:")
- local username = read()
- if(CheckUSR(username) == false)then
- term.setTextColor(colors.red)
- print("Unknown Username!")
- term.setTextColor(colors.white)
- sleep(1)
- os.reboot()
- else
- print("Password:")
- local password = read()
- if(CheckPassword(username, password) == false)then
- term.setTextColor(colors.red)
- print("Incorrect Password!")
- sleep(1)
- os.reboot()
- elseif(CheckPassword(username, password) == true)then
- term.setTextColor(colors.green)
- print("Welcome "..username.."!")
- term.setTextColor(colors.white)
- print("")
- SetUp()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement