Advertisement
CCninja86

Advanced Password Program v1.0.2 (debugging stage)

Mar 27th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.36 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.     local typedPassword = table.concat(charTyped) -- Concatenating the original version of the table "charTyped" and assigning it to the variable "typedPassword"
  28.     table.sort(charTyped) -- Sorting the table elements into numerical and alohabetical order
  29.     local decodedPassword = table.concat(charTyped) -- Concatenating the table elements into a string and assigning it to the variable "decodedPassword"
  30.     if typedPassword == "49e7FryO"
  31.     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
  32.       print ("Authorisation successful!") -- Printing the test "Authorisation successful!" to the display
  33.       sleep(2) -- Pausing for two seconds
  34.       rs.setOutput("left", true) -- Setting the output state of the Redstone on the left side of the computer to on
  35.       sleep(2) -- Pausing for two seconds
  36.       rs.setOutput("left", false) -- Setting the output state of the Redstone on the left side of the computer to off
  37.       os.shutdown() -- Shutdown computer to add extra security by preventing a user from typing "edit startup" in the console and changing the password.
  38.     end
  39.   end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement