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

Need help making a changepassword program.

Started by Rampage9112, 27 March 2012 - 12:31 AM
Rampage9112 #1
Posted 27 March 2012 - 02:31 AM
The New addition I'm adding to my basic operating system is a changepassword program. since I don't know much lua, I have no idea how to do this. (but I know it is possible to do). When starting the program, it should look like this:
 Current Password: (after putting in the correct password, it prints out the next line) New Password: Comfirm New Password: (If any of these are incorrect, it should reboot the computer.) 


This is the program that it edits the password from:
 term.clear()
 term.setCursorPos(1,1)
 write("---------------------------------------------") 
print("Welcome to RampageIndustries operating system V1.2 beta") 
print("---------------------------------------------") 
print("") 
print("Password:") 
correctpass = "admin" 
pass = read("*") 
if pass == (correctpass) 
then term.clear() 
term.setCursorPos(1,1) 
print("Welcome!") 
else print("") 
write("Incorrect! Rebooting!") 
sleep(2)
 os.reboot() end if correctpass == "admin" then
 term.clear() 
term.setCursorPos(1,1) 
print("It appears that you have the default password. Type changepass to change it. else sleep(1) end 

Thanks for helping, i'll add whoever helps with this' name to the credits.
Edited on 27 March 2012 - 12:35 AM
Tron #2
Posted 27 March 2012 - 04:09 AM
Not tested but this should work, and there is probably better ways to do it but this is what you do:
remove the correct pass thing
and at the beginning of your code do if ~= fs.exist("pass") then
correctpass = "admin"
else
correctpass = file:read("pass") –if that doesnt work then try without the () stuff and put a io.open("pass", "r" ) before it–
end
and then at the end of your code do:
shell.run("rm" , "pass")
tw = pcall(read())
io.open("pass", "w")
file:write(tw)
print("Password changed to: " tw .. )
coolblockj #3
Posted 27 March 2012 - 04:30 AM
^ There are quite a few things wrong in that…Here..
|
|


term.clear()
term.setCursorPos(1,1)
write("———————————————")
print("Welcome to RampageIndustries operating system V1.2 beta")
print("———————————————")
print("")
if not fs.exists("pass") then
print ("It seems you dont have a password set, set one now")
newpass = read()
file2 = io.open("pass", "w")
file:write(newpass)
file:close()
print ("Password changed, rebooting!")
os.reboot()
else
print("Password:")
file = io.open("pass", "r")
correctpass
= file:read()
pass = read("*")
if pass == (correctpass)
then term.clear()
term
.setCursorPos(1,1)
print("Welcome!")
else print("")
write
("Incorrect! Rebooting!")
sleep
(2)
os.reboot() end end
kamnxt #4
Posted 27 March 2012 - 07:28 AM
You should probably store it in .pass so it won't be visible when you run ls.
Rampage9112 #5
Posted 28 March 2012 - 03:27 AM
I copied it exactly, but I got this error message

startup:11: attempt to index ? (a nil value)
kamnxt #6
Posted 28 March 2012 - 01:26 PM
Try this code:

os.pullEvent = os.pullEventRaw --Disables ctrl + t
term.clear()
term.setCursorPos(1,1)
print("---------------------------------------------") 
print("Welcome to RampageIndustries operating system V1.2 beta") 
print("---------------------------------------------") 
print("") 
if fs.exists("/.pass") then
write("Password: ")
file = fs.open("/.pass","r") 
correctpass = file.readAll() 
file.close()
pass = read("*") 
if pass == correctpass 
then term.clear() 
term.setCursorPos(1,1) 
print("Welcome!") 
else print("") 
write("Incorrect! Rebooting!") 
sleep(2)
os.reboot() 
end 
else
print("No password set. Set one now.")
write("New password: ")
newPass = read("*")
file = fs.open("/.pass","w")
file.write(newPass)
file.close()
print("Password set, rebooting...")
sleep(2)
os.reboot()
end