Advertisement
CCninja86

Advanced Password Program v1.0 (debugging stage)

Mar 27th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. -- AdvancedPasswordProgram
  2.  
  3. os.pullEvent = os.pullEventRaw -- Program cannot be terminated until run
  4.  
  5. print ("Please enter password:") -- Prompt user to enter password into console
  6. local password = io.read()
  7.  
  8. charTyped = {} -- creating table with name "charTyped"
  9. position = 1 -- Assigning initial table position to 1
  10.  
  11. function hideCharacter() -- Creating fucntion to hide characters for added security
  12.   write ("*")
  13. end
  14.  
  15. while true do -- Always loop (allows for any length password)
  16.  event, character = os.pullEvent("char") -- If a character is pressed on the keyboard, execute the code below
  17.   if character ~= "" then -- Checking to make sure a character has been entered, if true execute the code below
  18.     hideCharacter()
  19.     table.insert(charTyped, position, character) -- Inserting typed character into the table "charTyped"
  20.     position = position + 1 -- Incrementing table position by 1
  21.   end
  22. end
  23.  
  24. while true do -- Always loop
  25.   event, scancode = os.pullEvent("key") -- If a key is pressed on the keyboard, execute the code below
  26.   if key == "28" then -- Checking to see if the key pressed was "Enter", if true execute the code below
  27.     table.sort(charTyped) -- Sorting the table elements into numerical and alohabetical order
  28.     local decodedPassword = table.concat(charTyped) -- Concatenating the table elements into a string and assigning it to the variable "decodedPassword"
  29.     if decodedPassword == "497eForY" then -- Checking to see if the sorted version of the table contains the correct numbers and letters, if true execute the code below
  30.       print ("Authorisation successful!") -- Printing the test "Authorisation successful!" to the display
  31.       sleep(2) -- Pausing for two seconds
  32.       rs.setOutput("left", true) -- Setting the output state of the Redstone on the left side of the computer to on
  33.       sleep(2) -- Pausing for two seconds
  34.       rs.setOutput("left", false) -- Setting the output state of the Redstone on the left side of the computer to off
  35.       os.shutdown() -- Shutdown computer to add extra security by preventing a user from typing "edit startup" in the console and changing the password.
  36.     end
  37.   end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement