Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- AdvancedPasswordProgram
- os.pullEvent = os.pullEventRaw -- Program cannot be terminated until run
- print ("Please enter password:") -- Prompt user to enter password into console
- local password = io.read()
- charTyped = {} -- creating table with name "charTyped"
- position = 1 -- Assigning initial table position to 1
- function hideCharacter() -- Creating fucntion to hide characters for added security
- write ("*")
- end
- while true do -- Always loop (allows for any length password)
- event, character = os.pullEvent("char") -- If a character is pressed on the keyboard, execute the code below
- if character ~= "" then -- Checking to make sure a character has been entered, if true execute the code below
- hideCharacter()
- table.insert(charTyped, position, character) -- Inserting typed character into the table "charTyped"
- position = position + 1 -- Incrementing table position by 1
- end
- end
- while true do -- Always loop
- event, scancode = os.pullEvent("key") -- If a key is pressed on the keyboard, execute the code below
- if key == "28" then -- Checking to see if the key pressed was "Enter", if true execute the code below
- local typedPassword = table.concat(charTyped) -- Concatenating the original version of the table "charTyped" and assigning it to the variable "typedPassword"
- table.sort(charTyped) -- Sorting the table elements into numerical and alohabetical order
- local decodedPassword = table.concat(charTyped) -- Concatenating the table elements into a string and assigning it to the variable "decodedPassword"
- if typedPassword == "49e7FryO"
- and decodedPassword == "497eForY" then -- Checking to see if the original version of the table is in the right order and the sorted version of the table contains the correct numbers and letters, if true execute the code below
- print ("Authorisation successful!") -- Printing the test "Authorisation successful!" to the display
- sleep(2) -- Pausing for two seconds
- rs.setOutput("left", true) -- Setting the output state of the Redstone on the left side of the computer to on
- sleep(2) -- Pausing for two seconds
- rs.setOutput("left", false) -- Setting the output state of the Redstone on the left side of the computer to off
- os.shutdown() -- Shutdown computer to add extra security by preventing a user from typing "edit startup" in the console and changing the password.
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement