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

Passworded computer (Upgrade)

Started by lewisholcombe, 03 April 2013 - 06:05 AM
lewisholcombe #1
Posted 03 April 2013 - 08:05 AM
So once again this is for my staff building :)/>
I have all my staff locks on each computer of there own password so they can use what they want but the only problem is i have to do there password for them and they have to tell me and i don't want it like that. I also want it so they can change it at any time.
Is there any way i can edit THIS SCRIPT to make it so they can do "changepassword" to change there password in the startup script.
I imagine this is relatively easy to do because all it needs to do is find the startup script and edit the second line down.
I could be totally wrong :(/>

NOTES
Im not asking anyone to make me a program (Unless they enjoy doing it and they want to edit mine) i just need the info on how to implement it into my script and into the new script to change it?
Cheers in advance!
JokerRH #2
Posted 03 April 2013 - 08:15 AM
I don't think that is neccessary.
#1 they could change the password themself
#2 You can open the file and read the password
(os.pullEvent = os.pullEventRaw prevents termination, but it is really simple to avoid it)
lewisholcombe #3
Posted 03 April 2013 - 08:36 AM
I don't think that is neccessary.
#1 they could change the password themself
#2 You can open the file and read the password
(os.pullEvent = os.pullEventRaw prevents termination, but it is really simple to avoid it)
I have os.pullEvent = os.pullEventRaw in there and as long as there is no disk drive next to the computer you cannot terminate the program.
The people in the offices are not experienced with cc and they asked me for this.
LBPHacker #4
Posted 03 April 2013 - 08:42 AM
Never ever rely on the unexperiencedness. (How the hell should have I put that? I'm Hungarian! You will understand nevertheless :D/>)
BabyCodder #5
Posted 03 April 2013 - 09:40 AM
I have started to create some code. like this but better :D/>
KRazpopov #6
Posted 03 April 2013 - 09:45 AM
I came up with this code now. It's surely not the most efficient or secure with the way it handles passwords, but I'm still fairly new to this stuff.
Just a forewarning, I haven't tested this code, since my video card is half-dead and I can't get CC-Emu or CC-Desk to work due to that.

Spoiler

os.pullEvent = os.pullEventRaw
local username = "User"
local isPassword = false
local SizeX, SizeY = term.getSize()
if fs.exists(".password") then
passread = fs.open (".password", "r")
local password = passread.readLine()
passread.close()
else
passwrite = fs.open (".password", "w")
while not isPassword do
  term.clear()
  term.setCursorPos(1, 1)
  write ("Please set a password: ")
  password =  read ("*")
  if password ~= nil then
   passwrite.writeLine (password)
   passwrite.close()
   isPassword = true
   print ("Password set.")
   -- Add code here to run what you need to
  else
   print ("Your password can not be blank.")
  end
end
end
while not isPassword do
term.clear()
write "Press 'Ctrl' to change your password."
term.setCursorPos (1,1)
print "User: " .. username
write "Password: "
term.setCursorPos(1, SizeY)
input = read ("*")
if input == password then
  isPassword = true
  --Add code here to run what you need to
else
  print "Incorrect password."
  print "Please try again."
end
bRead = true
while (bRead) do
  local sEvent, param = os.pullEvent("key")
  if sEvent == "key" then
   if param == 29 or param == 157 then
	local function ChangePass()
	 term.clear()
	 term.setCursorPos(1, 1)
	 write "Please input your current password: "
	 input = read ("*")
	 if input ==  password then
	  print ()
	  write "Please enter a new password: "
	  newPass = read("*")
	  if newPass ~= nil then
	   passwrite = fs.open (".password", "w")
	   passwrite.writeLine (newPass)
	   print "Password changed."
	  else
	   print "Your password can not be blank."
	   ChangePass()
	  end
	 else
	  print "Incrorrect password."
	  print "Press any key to try again."
	  read ()
	  ChangePass()
	 end
	end
   end
  end
end
end
BabyCodder #7
Posted 03 April 2013 - 10:45 AM
I've done the code. Come on the server and I'll show you.
PixelToast #8
Posted 03 April 2013 - 04:28 PM
a solution to the disk termination is to have a unreachable disk drive containing a startup disk with

shell.run("/startup")
you can also put the computer in a way that the only place you can click the computer is in the front
lewisholcombe #9
Posted 04 April 2013 - 04:20 AM
I came up with this code now. It's surely not the most efficient or secure with the way it handles passwords, but I'm still fairly new to this stuff.
Just a forewarning, I haven't tested this code, since my video card is half-dead and I can't get CC-Emu or CC-Desk to work due to that.

Spoiler

os.pullEvent = os.pullEventRaw
local username = "User"
local isPassword = false
local SizeX, SizeY = term.getSize()
if fs.exists(".password") then
passread = fs.open (".password", "r")
local password = passread.readLine()
passread.close()
else
passwrite = fs.open (".password", "w")
while not isPassword do
  term.clear()
  term.setCursorPos(1, 1)
  write ("Please set a password: ")
  password =  read ("*")
  if password ~= nil then
   passwrite.writeLine (password)
   passwrite.close()
   isPassword = true
   print ("Password set.")
   -- Add code here to run what you need to
  else
   print ("Your password can not be blank.")
  end
end
end
while not isPassword do
term.clear()
write "Press 'Ctrl' to change your password."
term.setCursorPos (1,1)
print "User: " .. username
write "Password: "
term.setCursorPos(1, SizeY)
input = read ("*")
if input == password then
  isPassword = true
  --Add code here to run what you need to
else
  print "Incorrect password."
  print "Please try again."
end
bRead = true
while (bRead) do
  local sEvent, param = os.pullEvent("key")
  if sEvent == "key" then
   if param == 29 or param == 157 then
	local function ChangePass()
	 term.clear()
	 term.setCursorPos(1, 1)
	 write "Please input your current password: "
	 input = read ("*")
	 if input ==  password then
	  print ()
	  write "Please enter a new password: "
	  newPass = read("*")
	  if newPass ~= nil then
	   passwrite = fs.open (".password", "w")
	   passwrite.writeLine (newPass)
	   print "Password changed."
	  else
	   print "Your password can not be blank."
	   ChangePass()
	  end
	 else
	  print "Incrorrect password."
	  print "Press any key to try again."
	  read ()
	  ChangePass()
	 end
	end
   end
  end
end
end
Im going to give this a try now. Thankyou very much for your time.