Jump to content

Login system using a db


tosfera

Recommended Posts

Hey guys,

I'm trying to base my entire project on a database but I'm walking against a problem right now. I already wrote a function to see if its an existing account, but to use the logIn function. You need to use the getAccount to get an account back for argument 2. But if they create an account, it gets saved into my MySQL. Is there anyway to return an account element from a db? Sofar I got this;

Server:

addEvent("isValidPlayer", true); 
addEventHandler("isValidPlayer", root, 
function(username, email, password) 
    openMysql() 
    local queryUserLogin = dbQuery( db, "SELECT * FROM users WHERE Users_Password = ? AND Users_Username = ?", password, username); 
    local resultUserLogin = dbPoll( queryUserLogin, -1 ) 
    for index, user in ipairs ( resultUserLogin ) do 
        logPlayer(user.Users_Username, user.Users_Password); 
    end  
    closeMysql() 
end); 
  
function logPlayer(username, password) 
    logIn(source, username, password); 
end 

easy client stuff;

function clientSubmitLogin()  
    local username = guiGetText(txt_username); 
    local email = guiGetText(txt_username); 
    local password = guiGetText(txt_password); 
    triggerServerEvent("isValidPlayer", getLocalPlayer(), username, email, password); 
end 

Link to comment

Why don't you just use the account functions then? It doesn't really look well with two systems of accounts mixed that way. There's no such thing as "account element", and all accounts of MTA account system are stored into the built-in database of MTA server.

Link to comment
Why don't you just use the account functions then? It doesn't really look well with two systems of accounts mixed that way. There's no such thing as "account element", and all accounts of MTA account system are stored into the built-in database of MTA server.

Finally! A reply! :lol::lol:

Anyway, I always thought that the accounts were stored in XML files? O_O Anyway, does the built-in db from MTA also saves user-ID's? Or just the serial cause if they do save the user-id's I'll just request all the data(after I saved it the same way) with the user_ID or serial. if thats possible?:P

Link to comment

Accounts used to be stored in XML files, but now the database is used. They are identified by name. If you want to have the two systems of accounts connected, then you need to use addAccount/removeAccount alongside the query which creates/destroys the account record in your MySQL database, and then you can modify your logPlayer function in such way that the player would be logged into the account of built-in system and also linked to the account of your database in some way.

But to me, connecting the systems seems messy. Why would you do that? You could either use one system to store the data or two systems for different purposes. For example, I'm making a gamemode with a custom account system which stores the data of the players (weapons, money, etc.) and I will also be using the built-in account system to log in as admin. The two systems used for different purposes aren't linked to each other in any way (for example, I can log in/out as admin while still using the same game account) and that is much better than having the gameplay achievements tied to the admin or moderator status.

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