Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- 420-login script
- by killerbyte12
- for use on OpenComputers mod in minecraft
- --]]
- -- GLOBAL vars
- ATTEMPTS = 3
- LOGGED_IN = false
- -- Ask for username
- function userInput()
- -- ask for username, covert input to all uppercase.
- print("Username: ")
- local input = string.upper(io.read())
- -- compare input to user files. Does this user exist?
- local user_exists = userExists(input)
- if user_exists == nil then
- print("Username invalid.")
- -- if user exists, lets ask for their password
- else
- print("Username found.")
- passInput(input)
- end
- end
- -- checks if a user file exists, returns nil if it doesnt.
- function userExists(user)
- local file = io.open(".dat/.usr/."..user..".txt", "r")
- if file ~= nil then
- file:close()
- end
- return file
- end
- -- Compare input to password on user file
- function getPass(user, pass)
- local file_contents = {}
- local pass_valid = false
- local file = io.open(".dat/.usr/."..user..".txt", "r")
- for line in file:lines() do
- file_contents[#file_contents+1] = line
- end
- file:close()
- -- password is on 3rd line
- if file_contents[3] == pass then
- pass_valid = true
- end
- return pass_valid
- end
- -- Ask for password
- function passInput(user)
- while ATTEMPTS > 0 do
- print("Password: ")
- local input = io.read()
- -- TODO md5 hash passwords
- local pass_valid = getPass(user, input)
- if pass_valid == true then
- print("Password accepted, logging in.")
- LOGGED_IN = true
- break
- else
- ATTEMPTS = ATTEMPTS - 1
- print("Password invalid. You have "..ATTEMPTS.." attempts left.")
- end
- end
- if ATTEMPTS <= 0 then
- print("You tried to many times, shutting down the system!")
- -- TODO, shutdown pc
- end
- end
- while LOGGED_IN == false do
- userInput()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement