This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
xteric's profile picture

Password log project

Started by xteric, 04 November 2015 - 12:09 PM
xteric #1
Posted 04 November 2015 - 01:09 PM
Hello! So I'm working on a password-based computer protection program and I've got the basics down!

The only problem is that I want to add a function that logs each incorrect password entered (and possibly what they tried to enter)

Could you please give me some tips of example code and explain to me how it works?

PS: The password is stored in a file. It is NOT embedded in the code.
valithor #2
Posted 04 November 2015 - 02:14 PM
Basically all you will have to do is set up a file to store the passwords, and when someone enters in a wrong password open the file in append mode and write it in there. Append mode just adds whatever you write in the file to the end of the file.


local function saveIncorrect(file,password)
  local file = fs.open(file,"a") --# opening the file in append mode
  file.writeLine(password) --# writing the password
  file.close() --# Always remember to close the file!
end

edit:

If you are confused about how to apply this:


local password = "Hello"

local function saveIncorrect(file,password)
  local file = fs.open(file,"a") --# opening the file in append mode
  file.writeLine(password) --# writing the password
  file.close() --# Always remember to close the file!
end

while true do
  local entered = read("*")
  if entered == password then
    --# correct password was entered
  else
    saveIncorrect("incorrectpasswords",entered)
  end
end
Edited on 04 November 2015 - 01:17 PM