Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- setup = false
- if not fs.exists("authKeySettings") then
- setup = true
- fs.makeDir("authKeySettings")
- print("Please set an admin password: ")
- password = read('*')
- local pass = fs.open("authKeySettings\password", "w")
- pass.write(password)
- pass.close
- print("Thank you. You may now log in with that password in the future to make keys.")
- print("Keys can only be made from this server, and nowhere else.")
- end
- if not setup then
- print("Please enter your password:")
- password = read('*')
- local pass = fs.open("authKeySettings\password", "r")
- if password = pass.readAll() then
- goodPass = true
- print("Password correct, logging you in.")
- else
- goodPass = false
- printError("Password incorrect. Please try again.")
- end
- end
- if not setup and goodPass then
- if not fs.exists("authKeys") then
- fs.makeDir("authKeys")
- end
- if not fs.exists("authIDs") then
- fs.makeDir("authIDs")
- end
- if args[1] == "createKey" then
- if not args[2] then
- printError("Useage: authKey createKey <Username>")
- else
- math.randomseed(os.time())
- ranKey = math.random(10000000)
- local keys = fs.open("authKeys/".. args[2], "w")
- keys.write(ranKey)
- keys.close()
- print("Your key is: ".. ranKey)
- print("User ".. args[2].. " can log in with the client using their username and key.")
- print("This key is valid for a one time use, and will never be usable again.")
- end
- elseif args[1] == "startListener" then
- while true do
- pcID, user, key = rednet.receive()
- if not fs.exists("authIDs\".. pcID) then
- if fs.exists("authKeys\".. user) then
- keyFile = fs.open("authKeys\".. user, "r")
- if key == keyFile.readAll) then
- keyFile.close()
- send(pcID, "Success")
- userPcID = fs.open("authIDs\".. pcID, "w")
- userPcID.write(user)
- userPcID.close()
- fs.delete("authKeys\".. user)
- else
- keyFile.close()
- send(pcID, "Failure: Key does not match user.")
- end
- else
- send(pcID, "Failire: User does not exist.")
- end
- elseif fs.exists("authIDs\".. pcID) then
- userFile = fs.open("authIDs\".. pcID, "r")
- user = userFile.readAll()
- userFile.close()
- rednet.send(pcID, "Welcome back, ".. user.. "!")
- end
- end
- elseif args[1] == "changePass" then
- print("Please set a new admin password: ")
- password = read('*')
- local pass = fs.open("authKeySettings\password", "w")
- pass.write(password)
- pass.close
- print("Thank you. You may now log in with that password in the future to make keys.")
- print("Keys can only be made from this server, and nowhere else.")
- else
- printError("Usage:")
- printError("Add new user: authKey createKey <Username>")
- printError("Start listening for connections: authKey startListener")
- printError("Change admin password: authKey changePass")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement