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

How To Read A Password From A Different File?

Started by SNWLeader, 11 November 2013 - 04:04 PM
SNWLeader #1
Posted 11 November 2013 - 05:04 PM
I am trying to get a passcode from a different file.
How do I do that?
Yevano #2
Posted 11 November 2013 - 05:54 PM
Use the FS API.


local handle = fs.open(filePath, "r")
local passcode = handle.readAll()
handle.close()
SNWLeader #3
Posted 11 November 2013 - 06:22 PM
Use the FS API.


local handle = fs.open(filePath, "r")
local passcode = handle.readAll()
handle.close()

great now how do I use this.
Yevano #4
Posted 11 November 2013 - 08:12 PM
Did you read the wiki article? What are you using this for specifically?
mrdawgza #5
Posted 12 November 2013 - 12:27 AM
Use what Yevano said for making the pass a variable

Use the FS API.


local handle = fs.open(filePath, "r")
local passcode = handle.readAll()
handle.close()


To use it in a program:

local handle = fs.open(filePath, "r") --loads the pass with read permissions
local passcode = handle.readAll() --takes the pass file above and reads it
handle.close() --closes the file

write("Password: ") --asks for the pass
iPass = read() --reads the input 

if iPass == passcode then --checks if the input pass matches the file
 print("Correct") --if it did
else --if the user input was anything else
 print("Denied") --if it didn't 
end --closes the if


Sorry if it's a little messy or wrong, I'm on my iPad.
SNWLeader #6
Posted 19 November 2013 - 09:27 PM
That is alright, and it works just perfectly. :D/>
Thanks guys.
Roboguy99 #7
Posted 20 November 2013 - 03:25 AM
Just what I needed too. Always glad for the invention of the forum and the ability to solve problems by looking at what other people did.