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

Hard to explain...

Started by ShadowLamp, 07 November 2014 - 09:51 PM
ShadowLamp #1
Posted 07 November 2014 - 10:51 PM
So I've coded a fairly simple login system to open a door.
Spoiler

os.pullEvent = os.pullEventRaw

term.clear()
term.setCursorPos(13,1)
print("Welcome To Shadow Inc.")
  sleep(1)
term.setCursorPos(1,2)
print("--------------------------------------------------")
sleep(1)
term.setCursorPos(1,4)
write("Enter Your Password: ")
local input = read("*")
if input == "somethingsomething...side" then
term.clear()
term.setCursorPos(14,1)
print("Welcome Back, Shadow")
term.setCursorPos(1,3)
print("--------------------------------------------------")
  redstone.setOutput("left", true)
  sleep(2)
  redstone.setOutput("left", false)
os.shutdown()
  elseif input == "Debugging" then
term.clear()
term.setCursorPos(7,1)
write("Logging Out of the Secure Network")
sleep(0.5)
term.clear()
term.setCursorPos(7,1)
write("Logging Out of the Secure Network.")
sleep(0.5)
term.clear()
term.setCursorPos(7,1)
write("Logging Out of the Secure Network..")
sleep(0.5)
term.clear()
term.setCursorPos(7,1)
write("Logging Out of the Secure Network...")
sleep(1)

term.setCursorPos(1,2)
print("--------------------------------------------------")
sleep(0.5)
term.clear()
term.setCursorPos(7,1)
print("Unsecure Debugging System Operational")
term.setCursorPos(1,2)
print("--------------------------------------------------")
sleep(0.5)
error()

elseif input == "Chrisyy" then
term.setCursorPos(15,1)
term.clear()
print("Welcome Back, Chrisy.")
term.setCursorPos(1,3)
print("---------------------------------------------------")
rs.setOutput("left",true)
sleep(2)
rs.setOutput("left",false)
os.shutdown()
else
  term.clear()
term.setCursorPos(8,1)
print("You are not Welcome at ShadowInc.")
term.setCursorPos(1,2)
print("---------------------------------------------------")
sleep(1)
term.clear()
term.setCursorPos(15,1)
print("Defences Activated.")
term.setCursorPos(1,2)
print("--------------------------------------------------")
sleep(0.5)
rs.setOutput("back",true)
sleep(2)
rs.setOutput("back",false)
os.shutdown()
end
  

I was wondering if there is a way to replicate this, but allow a user to chose their own name and password.

Further detail:


elseif input == "Chrisyy" then
Where is says "Chrisyy", that is the username of my friend. I manually wrote it in there, so, is there a way that I can code something, so that another user may type their desired username into a computer with the code, and it appear there, without them having to edit the raw code.

I want to be able to have a title screen with the option for a user to create a username and password. I can do the rest from there.

If anyone could help me, that would be great.

Thank you,
-billy
Dragon53535 #2
Posted 08 November 2014 - 12:18 AM
You would probably want to use files for this and save the username as the filename and the password inside it. A quick FS tutorial can be found Here.
Bomb Bloke #3
Posted 08 November 2014 - 12:40 AM
You'll also want to use tables to keep track of your users and their passwords.

Say for example you had this basic password access system:

local users = {["billylathamx"] = "yourPassword", ["Chrisyy"] = "Chrisy'sPassword"}

print("Enter username:")
local userInput = read()

print("Enter password:")
local passInput = read("*")

if users[userInput] == passInput then
	print("Logon accepted!")
end

You could then add to the user list like so:

print("Enter new username:")
local userInput = read()

print("Enter new password:")
local passInput = read("*")

users[userInput] = passInput

textutils.serialize() can be used to convert the "users" table to something that can be written to disk:

local myFile = fs.open("userList","w")
myFile.writeLine(textutils.serialize(users))
myFile.close()

And reading the data later is a similar process:

local myFile = fs.open("userList","r")
local users = textutils.unserialize(myFile.readAll())
myFile.close()
ShadowLamp #4
Posted 08 November 2014 - 12:56 AM
Will all of this work on the classic computers?
theoriginalbit #5
Posted 08 November 2014 - 01:02 AM
what do you mean by 'classic computers'?
Yuki__Asuna #6
Posted 08 November 2014 - 01:19 AM
I'm his friend Chrisy. He means Tekkit Classic computer craft Before the adv computer was implemented.
ShadowLamp #7
Posted 08 November 2014 - 01:20 AM
The none advanced computers.
theoriginalbit #8
Posted 08 November 2014 - 01:24 AM
yes it will work with normal computers, the difference between normal and advanced is only the ability to do colours, and the ability to click the screen.
ShadowLamp #9
Posted 08 November 2014 - 01:30 AM
Ah, I thought they had new API's and stuff…Thank you! :D/>
theoriginalbit #10
Posted 08 November 2014 - 02:05 AM
there are a few new APIs between Tekkit Classic and the latest ComputerCraft, however of all the new APIs only the multishell API is specific to Advanced Computers. everything used within Bomb Blokes example is standard to any version of ComputerCraft Lua.
Edited on 08 November 2014 - 01:05 AM