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

login

Started by Rougeminner, 09 June 2014 - 06:39 AM
Rougeminner #1
Posted 09 June 2014 - 08:39 AM
I am having some trouble working out eh login system for my Operating system. I am theming it off of Mac OSX's boot up login in screen but i am having a problem figuring out how to check if the password belongs to the correct user name. (at the moment there is only Rougeminner and guest).



and i also want to know how to allow guest account only read only access

PLEASE HELP ME FIX THIS PROBLEM
Rougeminner
Edited on 09 June 2014 - 06:41 AM
Goof #2
Posted 09 June 2014 - 09:50 AM
For the password checking do:


local pass="1234"
local user="4321"
local input_user = read()
local input_pass = read("*") -- the star, so the password isnt visible
-- now to the comparrison
---------------------------Remember this "and"
if input_user == user and input_pass == pass then
 --- your code if everything was entered correctly
else
 -- show invalid login
end


For the readonly access you have to ask another, since im not much familar with overwriting all apis
(Before you can make it readonly you can also overwrite fs.isReadOnly to return true if its a guest account.)

I hope i could help so far
KingofGamesYami #3
Posted 09 June 2014 - 01:09 PM
A better way to check passwords: tables!

local users = {}
users["Rougeminer"] = "myPassword"
local input = read()
if users[input] == "myPassword" then
 --A login
elseif users[input] then
  --An invalid password
else
  --An invalid username
end


For the read only thing, that's a little harder. You'll need to overwrite the fs api in order to do something like that. I can provide some basic advice in this area.

local oldfs = {} --#this bit creates a "backup" of the fs functions, so you can be free to overwrite the originals.  Don't forget this
for k, v in pairs( fs ) do
 oldfs[k] = v
end
function fs.move( fPath, tPath )
 if fPath:sub( 1, 1 ) == ":" --#change this if you like, I'm using a colon ( : ) to name locked files.  ei :login or :term  Additionally, I'm using the string.sub( str, startnum, endnum ) in it's colen notation form on the variable fPath
  --#this file is locked
 else
  --#this file isn't locked so...
 oldfs.move( fPath, tPath )
 end
end
Of course, you will want to overwrite much more than just one function, but I'm not going to do this all for you xD.
SquidDev #4
Posted 09 June 2014 - 01:22 PM
Of course you should hash the passwords for extra security: Use GravityScore's SHA-256 for this.
Rougeminner #5
Posted 10 June 2014 - 04:57 AM
THANK YOU SO MUCH, everybody. i am glad to get help on this i will keep this thread live for anymore problems i may come across.

@squiddev thanks i will look into to that(mostly to tray and learn it :)/> )
@KingofGames i may need a little more of a description on your code to set the user access (override fs api)
edit @kingofgames ok i looked a little harder at in and i understand it (mostly) so i need to now Know how to set it so you can not edit it as guest.
Edited on 10 June 2014 - 02:59 AM
Rougeminner #6
Posted 10 June 2014 - 05:07 AM
i have a new(noob) problem that i can not fix it is the login script for now (there will be indefinite changes to implement more code such as listed above)


-- All Variable defintions here
local password = 'admin'
local hint = 'access level'
local try = 0
-- All functions here
function tries()
if try >= 3 and try <=5 then
term.setCursorPos(3,1)
print(hint)
elseif try == 6 then
print("incorrect reseting")
sleep(.5)
for i = 1 ,121 do
term.setBackgroundColor(colors.black)
local time = 121
time = time-1
print("The computer is locked for ",tostring(time),' seconds left')
os.reboot()
end
end
end
function initial()
term.setCursorPos(1,1)
print("Password")
term.setCursorPos(2,1)
input1 = read()
if input1 == password then
paintuitls.drawLine(2,1,2,8,colors.blue)
sleep(.2)
paintutils.drawLine(2,1,2,8,colors.white)
sleep(.2)
paintutils.drawLine(2,1,2,8,colors.blue)
sleep(3.4)
term.clear()
print("logged in")
elseif not(input1 == password) then
try = try+1
tries()
end
end
i feel really stupid right now for having to ask about a COMPUTER LOCK!
IGNORE EVERYTHING THE SECOND I POSTED THIS I SAW I FORGOT TO CALL THE FUNCTION :P/>
Edited on 10 June 2014 - 03:08 AM