Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Stops the people terminating the program
- local pullEvent = os.pullEvent
- os.pullEvent = os.pullEventRaw
- --Create variables for later
- local osver = "OS version"
- local osname = "openBananaOS"
- local programs = "[Programs] [Time] [Logout]"
- local times = ""
- local name = ""
- local username = ""
- local password = ""
- local i = 0
- local confirmpassword = ""
- local input2 = ""
- local input1 = ""
- local usertable = {}
- local login = 0
- local j = 0
- local n = 0
- local user = ""
- local pass = ""
- local permission = ""
- local found = "false"
- --Clear function
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function time()
- times = os.date("!%H:%M:%S")
- clear()
- slowPrint(times)
- end
- --Shorten textutils.slowPrint
- function slowPrint(msg)
- textutils.slowPrint(msg)
- end
- --Shorten textutils.slowWrite
- function slowWrite(msg)
- textutils.slowWrite(msg)
- end
- --Center Text
- function centerText(text)
- local x,y = term.getSize()
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x/2) - (text:len() / 2)), y2)
- write(text)
- end
- function string:split(sSeparator, nMax, bRegexp)
- assert(sSeparator ~= '')
- assert(nMax == nil or nMax >= 1)
- local aRecord = {}
- if self:len() > 0 then
- local bPlain = not bRegexp
- nMax = nMax or -1
- local nField=1 nStart=1
- local nFirst,nLast = self:find(sSeparator, nStart, bPlain)
- while nFirst and nMax ~= 0 do
- aRecord[nField] = self:sub(nStart, nFirst-1)
- nField = nField+1
- nStart = nLast+1
- nFirst,nLast = self:find(sSeparator, nStart, bPlain)
- nMax = nMax-1
- end
- aRecord[nField] = self:sub(nStart)
- end
- return aRecord
- end
- --System Setup on first boot
- if fs.exists("users.dat") == false then
- slowPrint(osname.." has not been setup yet!")
- slowPrint(osname..".setup initializing...")
- sleep(1)
- clear()
- slowWrite("[SetuPro] What is your name? ")
- name = read()
- clear()
- slowWrite("[SetuPro] Please enter your desired username: ")
- username = read()
- i = 0
- while i == 0 do
- slowWrite("[SetuPro] Please enter your desired password: ")
- password = read("*")
- slowWrite("[SetuPro] Please confirm your password: ")
- confirmpassword = read("*")
- if password == confirmpassword then
- i = 1
- clear()
- slowPrint("[SetuPro] Passwords match")
- else
- clear()
- slowPrint("[SetuPro] Passwords do not match, please try again")
- end
- end
- input = name..":"..username..":"..password..":owner"
- usertable = {}
- table.insert(usertable, 1, input2)
- input2 = textutils.serialize(usertable)
- local writefile = fs.open("users.dat","w")
- writefile.write(input2)
- writefile.close()
- end
- local tmp = fs.open("users.dat","r")
- local users = tmp.readAll()
- tmp.close()
- local userlist = textutils.unserialize(users)
- while true do
- --Booting Screen
- clear()
- term.setCursorPos(1,4)
- centerText("[ "..osname.." ]")
- term.setCursorPos(1,6)
- centerText(" "..osver.." ")
- sleep(2)
- i = 0
- login = 0
- while i == 0 do
- clear()
- print(osname..osver.."(TM)")
- slowWrite("Please enter your username: ")
- user = read()
- slowWrite("Please enter your password: ")
- pass = read("*")
- j = 0
- n = 1
- found = false
- while j == 0 do
- test = userlist[n]
- test = string.split(test,":")
- if test == nil then
- j = 1
- else
- name = test[1]
- username = test[2]
- password = test[3]
- permission = test[4]
- if username == user and password == pass then
- found = true
- j = 1
- else
- n = n+1
- end
- end
- end
- if found == false then
- slowPrint("Username/Password incorrect, please try again")
- sleep(2)
- clear()
- else
- i = 1
- slowPrint("Username and password correct!")
- sleep(1)
- clear()
- end
- end
- clear()
- while login == 1 do
- clear()
- print(osname..osver.."(TM)")
- print("Welcome to" ..osname.." "..name)
- sleep(1)
- slowPrint("Type 'programs' to view the programs avaliable")
- slowWrite("Please enter a program: ")
- input1 = read()
- input2 = string.lower(input1)
- if input2 == "programs" then
- clear()
- slowPrint("Avaliable programs: ")
- slowPrint(programs)
- print("")
- slowPrint("Press enter to continue...")
- read()
- elseif input2 == "logout" then
- clear()
- login = 0
- slowPrint("Logged out!")
- elseif input2 == "time" then
- clear()
- slowPrint("The time in UTC is: ")
- time()
- else
- slowPrint(input2.." is not a recognised program")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment