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

Table.insert not working properly

Started by HaddockDev, 20 October 2016 - 11:46 PM
HaddockDev #1
Posted 21 October 2016 - 01:46 AM
I have been fiddling with my *nix like OS called Snapp, and I'm currently working on support for users.
I have two programs, called login and adduser respectively.

Login asks for the username and password, and then passes it on to a kernel function called AttemptLogin.
For an example:

print("Hey, I need root access! Please tell me your password!")
write("Password: ")
pswd = read()

--Somewhere's here it would get encrypted...
--Passed onto Snapp
if Snapp.API.Users.AttemptLogin("root", pswd) then
  print("kthx")
else
  print("y u no correct password")
end
That stuff works all fine, but when it comes to adding users it just doesn't care.

if(#tArgs < 1) then
printError("no username specified")
end

write("Username: ")
u = read()
write("Enter password: ")
p = read(" ")

--This is where it "adds the user"
table.insert(Snapp.Users, {username = u, root = false, password = p}) --for example, (username = "johnsmith", root = false, password = "secur3Passw0rd")
print("Added user " .. u)
If I look into the Snapp.Users table, it actually exists: (I made a test account named "apple")

lua> for k,v in ipairs(Snapp.Users) do print(v.username) end
root
apple --my account does exist, so I should be able to login right?
But according to login, it doesn't exist:

login: apple
password: *****
Could not find that user, login failed. --but my account exists?
Using the "root" account works perfectly though.

To be honest I don't know what I done wrong, so if you could explain anything to me, thanks in advance.
Edited on 23 October 2016 - 06:23 PM
Lyqyd #2
Posted 21 October 2016 - 02:10 AM
Please post the actual code.