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

User auth system doesn't work.

Started by Admicos, 19 December 2015 - 02:13 PM
Admicos #1
Posted 19 December 2015 - 03:13 PM
EDIT: I did some stuff and the issue solved itself. I still don't know why this happened but its fixed

So, while doing some stuff, i decided to add an user system to my computer. Now, creating users aren't a problem, but i have a weird error in the authenicator.

So, because i wanted to be secure, i used Sha1 and salting. But some reason, the authenicator only works on ONE salt.

It does not pop up an error message, just says the password is wrong.

User creation code:

function makeUser(name, password)
local salt = libRand.randomString(5)
fs.makeDir("home/" .. name)
salty = fs.open("home/" .. name .. "/.salty-" .. salt, "w")
  salty.write(Sha1.Sha1(password .. salt))
salty.close();
for k, v in pairs(fs.list("/etc/skel/home")) do
  fs.copy("/etc/skel/home/" .. v, "/home/" .. name .. "/" .. v)
end
end

User authenication code:

function authUser(name, password)
for i, v in pairs(fs.list("home/" .. name)) do
  if (stringStuff.starts(v, ".salty-")) then
   q = stringStuff.split(v,"-")
   enteredPass = Sha1.Sha1(password .. q[2])
   salty = fs.open("home/" .. name .. "/.salty-" .. q[2], "r")
	savedPass = salty.readAll()
   salty.close();
   if enteredPass == savedPass then
	_G.usr["current"] = name
	return true
   else
	return false
   end
  end
end
end

and here is the only working salt file:

Filename: .salty-eEu9X
Content: aca2c0f788fa6e92c0c26d05457e92cfa663908f

(It's the Sha1+salt of 123456, btw)

I think i can give some other info if needed.
Edited on 19 December 2015 - 04:59 PM
DannySMc #2
Posted 21 December 2015 - 10:47 PM
EDIT: I did some stuff and the issue solved itself. I still don't know why this happened but its fixed

So, while doing some stuff, i decided to add an user system to my computer. Now, creating users aren't a problem, but i have a weird error in the authenicator.

So, because i wanted to be secure, i used Sha1 and salting. But some reason, the authenicator only works on ONE salt.

It does not pop up an error message, just says the password is wrong.

User creation code:

function makeUser(name, password)
local salt = libRand.randomString(5)
fs.makeDir("home/" .. name)
salty = fs.open("home/" .. name .. "/.salty-" .. salt, "w")
  salty.write(Sha1.Sha1(password .. salt))
salty.close();
for k, v in pairs(fs.list("/etc/skel/home")) do
  fs.copy("/etc/skel/home/" .. v, "/home/" .. name .. "/" .. v)
end
end

User authenication code:

function authUser(name, password)
for i, v in pairs(fs.list("home/" .. name)) do
  if (stringStuff.starts(v, ".salty-")) then
   q = stringStuff.split(v,"-")
   enteredPass = Sha1.Sha1(password .. q[2])
   salty = fs.open("home/" .. name .. "/.salty-" .. q[2], "r")
	savedPass = salty.readAll()
   salty.close();
   if enteredPass == savedPass then
	_G.usr["current"] = name
	return true
   else
	return false
   end
  end
end
end

and here is the only working salt file:

Filename: .salty-eEu9X
Content: aca2c0f788fa6e92c0c26d05457e92cfa663908f

(It's the Sha1+salt of 123456, btw)

I think i can give some other info if needed.

I can help if you need, but can you add all the code in a file on pastebin, then send me the code with an example of what you are doing? Also I would suggest using SHA256, which is documented all over the CCForums? Go to APIs and Utilities under Programs section.

I also might add make sure when you concatenate the strings you use tostring() because this means even if the text is nil or something else, this will still add it to the string.
Edited on 21 December 2015 - 09:49 PM
Bomb Bloke #3
Posted 21 December 2015 - 11:27 PM
EDIT: I did some stuff and the issue solved itself. I still don't know why this happened but its fixed
DannySMc #4
Posted 21 December 2015 - 11:44 PM
EDIT: I did some stuff and the issue solved itself. I still don't know why this happened but its fixed
One day, maybe one day I shall read it all… >.<