Jump to content

Login


Recommended Posts

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
Link to comment

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.

Link to comment
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 

Link to comment

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

Link to comment

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.

Link to comment

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...