Jump to content

Login


Recommended Posts

Posted (edited)

Hai, I'm tryina' make a login system. No idea how to say that if username and password are in a .xml file, then login. This is the code cut into a piece. I've got the usern and passw defined and they are added when registered. Or should be. Didn't test it yet.

function login( thePlayer, command, username, password ) 
  
    load = xmlLoadFile ( "accl.xml" ) 
        child = xmlFindChild ( group, "user", 0 ) 
         
            if (usern and passw == load)    then 
                menu 
            else 
                label[2] = guiCreateLabel(insertcoordshere, "Please type a correct username/password!") 
                    setTimer(label[2], 5000, 3) 
            end 
end 

And this is the whole code:

showCursor(true) 
fadeCamera(true) 
setCameraMatrix(insertCityHall/PDcoordshere) 
user = guiCreateEdit(insertcoordshere) 
pass = guiCreateEdit(insertcoordshere) 
register = guiCreateButton(insertcoordshere) 
login = guiCreateButton(insertcoordshere) 
addEventHandler( "onClientGUIClick", register, register ) 
addEventHandler( "onClientGUIClick", login, login ) 
  
  
function register() 
     
     
    local usern = guiGetText( user ) 
    local passw = guiGetText( pass ) 
        if (username>3 or password>3)   then 
            label[1] =  guiCreateLalbel(insertcoordshere, "Please write a longer username/password!") 
                setTimer(label[1], 5000, 3) 
    else 
        xmlLoad = xmlLoadFile ( "accl.xml" ) 
    end 
        if xmlRootTree  then 
            xmlNodeSetValue ( "user", usern, passw ) 
        else 
            return 
        end 
end 
  
function login( thePlayer, command, username, password ) 
  
    load = xmlLoadFile ( "accl.xml" ) 
        child = xmlFindChild ( group, "user", 0 ) 
         
            if (usern and passw == load)    then 
                menu 
            else 
                label[2] = guiCreateLabel(insertcoordshere,"Please type a correct username/password!") 
                    setTimer(label[2], 5000, 3) 
            end 
end 
         
         
     
  
     

Note: where it's written "insertcoordshere" or anything to do with that, it means I will write the coordinates later.

Edited by Guest
Posted

kimmis, you didn't get what he's trying to do.

If I'm right, he's trying to save and load the account details from a CLIENT SIDE XML fiel called "acl.xml", but that doesn't mean is the access control list.

Posted

What im not trying to increase my stupid post count ... and im not making fun of you but for a normal login panel you dont need a xml file to store them ...

Posted

He's trying to save the USERNAME and PASSWORD so when he joins again, he doesn't have to type it AGAIN AND AGAIN.

What you say makes no sense.

Posted

Thanks castillo now i understand XDD i see what i said made no sense now sorry for it...

But idk what the probelm is here im a bit to tired now since i dont understand a shit

Posted

Actually this is my basic login GUI. What you do is write your username and password on the GUI edits, click register, which saves your username and account into my account list(accl.xml) and then, you login. I'm trying to make it search the username and password, when you input something into the edits and click login and if the username and password exist, then it logs you in. THAT'S ALL. And I'm stuck on ONE BIT of problem. How do I make the script search the accl.xml. If you can help me with that, you are so helpful and you will be the most epic person in the world.

Sorry for exaggerating, I just want my script to work ;P.

Posted

Ah ok well i never worked with more advanced xml than one node so i think u should wait for someone else than me to answer

Posted
function saveLoginToXML(username, password) 
    xmlFile = xmlLoadFile ("userdata.xml") 
    if not xmlFile then 
        xmlFile = xmlCreateFile("userdata.xml", "login") 
    end 
    local usernameNode = xmlFindChild (xmlFile, "username", 0) 
    local passwordNode = xmlFindChild (xmlFile, "password", 0) 
    local success = xmlNodeSetValue (usernameNode, tostring(username)) 
    local success2 = xmlNodeSetValue (passwordNode, tostring(password)) 
    if success and success2 then 
        xmlSaveFile(xmlFile) 
    end 
    xmlUnloadFile (xmlFile) 
end 
  
function loadLoginFromXML() 
    xmlFile = xmlLoadFile ("userdata.xml") 
    if not xmlFile then 
        xmlFile = xmlCreateFile("userdata.xml", "login") 
    end 
        local usernameNode = xmlFindChild (xmlFile, "username", 0) 
        local passwordNode = xmlFindChild (xmlFile, "password", 0) 
        if usernameNode and passwordNode then 
            return xmlNodeGetValue(usernameNode), xmlNodeGetValue(passwordNode) 
        else 
            return "", "" 
    end 
    xmlUnloadFile (xmlFile) 
end 

Posted

Right. Now... How do I make it so that the player logins, when he clicks on a login button which I'll create? The loadlogin thing should be the login function. And if the username and password are entered correctly, the player should login into his account and some other GUI, which I'll make later will be shown and he can select and do stuff. No point in going further. Just help. :P

Posted

These two functions should be used like this:

On login button clicked -> saveLoginToXML(username, password)

When player joins(onClientResourceStart) -> loadLoginFromXML() which returns two values (username and password).

Posted

I'll say it clearly: this IS a login system made by me. I'm trying to make the "Register" and "Login" buttons work. I made a GUI which has two edit boxes: Username and Password. You write your username and password in those two boxes and press register. The register button send the username and password to the .xml file, which stores them. I need to make it so that if the username and password are in the .xml file, you can login. That's ALL.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...