Improvement on the improvement.
local password = "1234" -- declared here to make the program easier to edit
local side = "left" -- same
os.pullEvent = os.pullEventRaw -- just need to do this once, no point having it in the loop
while true do
-- moved these here; need to do them every time or the program is useless
term.write("Password: ")
local input = read() -- use local unless you NEED a global, which you ideally shouldn't.
--
if input == password then --don't use () around strings, pointless and slightly confusing syntax
print("Access granted.") --moved here, we want it to show at once rather than 4 seconds later; fixed capitalization and punctuation
rs.setOutput(side, true)
sleep(3)
rs.setOutput(side, false)
sleep(1)
else
print("Incorrect password.") -- capitalization and punctuation
sleep(2)
end
end
You could also do "if read() == password then" since you're not using the input variable anywhere else. That's just a remark though, not a recommendation.
Other tips:
- Don't show the password in plain text - read more about read()
- Modifying the program so you can actually exit it without a special disk without compromising the "security" is left as an exercise to the reader. Has to do with what you're doing with pullEvent..