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

How To Make Settings?

Started by mrdawgza, 25 September 2013 - 06:21 AM
mrdawgza #1
Posted 25 September 2013 - 08:21 AM
I have an operating system, still in development.
Now I have a menu called options,
Now I have a account system, with at default 3 accounts.
They all have default names, so how can I get a option in the options menu thatcan change the username or password of the account?
If this can be done, then you don't have to go all the way into the files and stuff.
amtra5 #2
Posted 25 September 2013 - 08:41 AM
Step 1: Input old username
Step 2: Input old password
Step 3: Hash & salt old password
Step 4: Compared hashed and salted password with hashed and salted password in a file
Step 5: If they are the same, ask for new username
Step 6: Ask for new password
Step 7: Hash & salt new password
Step 8: Change the old username & hashed & salted old password with new one in the file

Although this doesn't stop any other program from editing/reading the user/hashed & salted password file
mrdawgza #3
Posted 25 September 2013 - 08:53 AM
Could you show me an example code?
MR_nesquick #4
Posted 25 September 2013 - 03:44 PM
i don't know how you are saving the usernames and passwords, but i got an example if you're using tables. (reading "table issue".. so close :P/>)

Example:
Spoiler

local tUsers={
--usernames,passwords	 --list of usernames and password
{"abc","123"},
{"abba","abc"},
{"cba","dde"},
}
function clear()	   -- clears the screen
term.setCursorPos(1,1)
term.clear()
end

clear()		  -- clears the screen
print("Username: ")
print("Password: ")
term.setCursorPos(10,1)
local oldUse = read()	  --input username
term.setCursorPos(10,2)
local oldPas = read("*")	 -- input old password
for i = 1,#tUsers do
if oldUse == tUsers[i][1] and oldPas == tUsers[i][2] then  -- compare username and password
  clear()		-- clears the screen
  print("New password: ")
  term.setCursorPos(14,1)
  local newPass1 = read("*")   --input new password #1
  clear()		-- clears the screen
  print("New Password: ")
  print("Type your new password again")
  sleep(.2)
  term.setCursorPos(14,1)
  local newPass2 = read("*")   -- input new password #2
   if newPass1 == newPass2 then--compares your new passwords
	tUsers[i][2] = newPass1 -- if true change your old password
   else
	clear()	  -- clears the screen
	print("Did you misspell your new password?")
	print("Please try again :)/>/>/>/>/>/>/>/>/>")
	sleep(1.5)
   end
  clear()		-- clears the screen
  print("Username:",tUsers[i][1])
  print("New Pass:",tUsers[i][2])
end
end
<pastebin get example>
theoriginalbit #5
Posted 25 September 2013 - 03:50 PM
i don't know how you are saving the usernames and passwords, but i got an example if you're using tables.

Example:
Spoiler

local tUsers={
--usernames,passwords	 --list of usernames and password
{"abc","123"},
{"abba","abc"},
{"cba","dde"},
}
function clear()	   -- clears the screen
term.setCursorPos(1,1)
term.clear()
end

clear()		  -- clears the screen
print("Username: ")
print("Password: ")
term.setCursorPos(10,1)
local oldUse = read()	  --input username
term.setCursorPos(10,2)
local oldPas = read("*")	 -- input old password
for i = 1,#tUsers do
if oldUse == tUsers[i][1] and oldPas == tUsers[i][2] then  -- compare username and password
  clear()		-- clears the screen
  print("New password: ")
  term.setCursorPos(14,1)
  local newPass1 = read("*")   --input new password #1
  clear()		-- clears the screen
  print("New Password: ")
  print("Type your new password again")
  sleep(.2)
  term.setCursorPos(14,1)
  local newPass2 = read("*")   -- input new password #2
   if newPass1 == newPass2 then--compares your new passwords
	tUsers[i][2] = newPass1 -- if true change your old password
   else
	clear()	  -- clears the screen
	print("Did you misspell your new password?")
	print("Please try again :)/>/>/>/>/>/>/>/>/>")
	sleep(1.5)
   end
  clear()		-- clears the screen
  print("Username:",tUsers[i][1])
  print("New Pass:",tUsers[i][2])
end
end
<pastebin get example>
If you're going to do it that way, you may as well use lookup tables!

Very Basic Example
Spoiler

local accounts = {
  ["Username"] = "password",
  ["TheOriginalBIT"] = "You_wi$h",
}

write("Username: ")
local user = read()
write("Password: ")
local pass = read()
if accounts[user] == pass then
  print("Account info correct")
else
  print("Nope, username or password is wrong!")
end