Jump to content

MySQL


Recommended Posts

I have a script, that someone gave of me of the basicRP gamemode, although it had been modified, he had gave me it to learn scripting and to develop it, I was confused when I checked his login screen, I realised a code which I had never encountered, could anyone tell me how this code works?

  
 local result, numrows, errmsg = dbPoll(queryCreds, 0) 
 if result and numrows == 1 then 
    result = result[1] 
  
local rPass = string.lower(md5(string.lower(md5(password)) .. result.salt)) 

Link to comment

dbPoll - It is used for querying. Use -1 which will wait till result is ready and then return. Currently there is 0 which will instantly return and may sometimes return nil. So use -1.

Line 2 checks if result is success and checks only if 1 row is returned.

Line 4 result variable is set to first row or in other words, result variable has the first row data.

Line 6 string.lower will make convert the string to lower case letters. For md5, check https://wiki.multitheftauto.com/wiki/Md5

Link to comment

How would this be stored in the database? My friend used a php website for a UCP to register, I have created a IG register button, although I have no idea how to store it regarding the md5 salt and password..

Link to comment
How would this be stored in the database? My friend used a php website for a UCP to register, I have created a IG register button, although I have no idea how to store it regarding the md5 salt and password..

You need to use dbQuery first. Please check the second post: https://forum.multitheftauto.com/viewtopic.php?f=148&t=38203

My skype is: majid.sheikh95

Keep in mind, I'll only reply when I'm free. :)

Link to comment

I have a piece of code which is used to fetch the Login Results...

connection = dbConnect("mysql", "dbname=" .. get("@MYSQL_DB") .. ";host=" .. get("#MYSQL_HOST"), get("#MYSQL_USER"), get("#MYSQL_PASS")) 
   
dbQuery(loginCallback1, { 
    player, 
    username, 
    password, 
    rememberMe 
  }, connection, "SELECT userid, username, usergroupid, password, salt FROM user WHERE username = ?", username) 
  

Link to comment
I have a piece of code which is used to fetch the Login Results...
connection = dbConnect("mysql", "dbname=" .. get("@MYSQL_DB") .. ";host=" .. get("#MYSQL_HOST"), get("#MYSQL_USER"), get("#MYSQL_PASS")) 
   
dbQuery(loginCallback1, { 
    player, 
    username, 
    password, 
    rememberMe 
  }, connection, "SELECT userid, username, usergroupid, password, salt FROM user WHERE username = ?", username) 
  

You can use UPDATE. Check w3school sql tutorial. Google it. You will find everything you need to know.

Link to comment

I want add a new record in the column for when I register

My database is something like;

    dbQuery( connection, "INSERT INTO user (userid, username, usergroupid, password, salt, online, admin) VALUES(?, ?, 1, ?, ?, 1, 0)") 

When I click register it sends this to my server side...

function registerClick(btn, state) 
   local username = tostring(guiGetText(loginGUI.username)) 
   local password = tostring(guiGetText(loginGUI.password)) 
    if btn == "left" and state == "up" then 
    triggerServerEvent("tryRegister", username, password) 
  end 
end 

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