SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Security #1 | |
| 2 | -- Password lock | |
| 3 | -- Code written by jag_e_nummer_ett | |
| 4 | - | function checkLogin(pass) |
| 4 | + | |
| 5 | - | -- Yes, very easy to hack... |
| 5 | + | |
| 6 | - | if pass == "butler" then |
| 6 | + | |
| 7 | - | return true |
| 7 | + | |
| 8 | - | else |
| 8 | + | |
| 9 | - | return false |
| 9 | + | local password = "password" |
| 10 | local inputPass = "" | |
| 11 | local tries = 5 | |
| 12 | while inputPass ~= password do | |
| 13 | term.clear() | |
| 14 | if tries < 5 then | |
| 15 | term.setCursorPos(3,5) | |
| 16 | - | while not checkLogin(inputPass) do |
| 16 | + | print("Incorrect password!")
|
| 17 | - | term.clear() |
| 17 | + | end |
| 18 | - | if inputPass ~= "" then |
| 18 | + | term.setCursorPos(3,2) |
| 19 | - | term.setCursorPos(3,2) |
| 19 | + | print("Please enter password")
|
| 20 | - | print("Wrong password!")
|
| 20 | + | term.setCursorPos(3,4) |
| 21 | - | end |
| 21 | + | print("Tries left: "..tries)
|
| 22 | - | term.setCursorPos(3,3) |
| 22 | + | term.setCursorPos(3,3) |
| 23 | - | print("Password: ") -- 10 char long
|
| 23 | + | write("Password: ")
|
| 24 | - | |
| 24 | + | inputPass = read("*")
|
| 25 | - | -- Now comes the input |
| 25 | + | tries = tries - 1 |
| 26 | - | term.setCursorPos(13,3) |
| 26 | + | if tries == 0 then |
| 27 | - | inputPass = read("*")
|
| 27 | + | return false |
| 28 | end | |
| 29 | end | |
| 30 | return true | |
| 31 | - | print("Correct password!")
|
| 31 | + | |
| 32 | ||
| 33 | if login() then | |
| 34 | - | term.setCursorPos(1,1) |
| 34 | + | |
| 35 | term.setCursorPos(3,2) | |
| 36 | print("Login successful!")
| |
| 37 | - | login() |
| 37 | + | |
| 38 | else | |
| 39 | term.clear() | |
| 40 | term.setCursorPos(3,2) | |
| 41 | print("Login failed!")
| |
| 42 | sleep(1.5) | |
| 43 | os.shutdown() | |
| 44 | end | |
| 45 | ||
| 46 | os.pullEvent = oldPull; |