PHP UCP
#1

pawn Code:
public OnMysqlQuery(resultid, spareid, MySQL:handle)
{
    switch (resultid)
    {
        case MYSQL_RESULT_LOGIN:
        {
            mysql_store_result();
            new
                rows = mysql_num_rows(),
                query[300],
                playerName[24]
            ;
           
            if(rows > 0)
            {
                /*
                    format(query, sizeof(query), "SELECT * FROM `playerdata` WHERE `playerName` = '%s'", playerName);
                    mysql_query(query);
                    mysql_store_result();
                    mysql_fetch_row(row, "|");
                    explode(row, field, "|");
                    mysql_free_result();
                */

               
                GetPlayerName(spareid, playerName, 24);
               
                format(query, sizeof(query), "SELECT * FROM `playerdata` WHERE playerName = '%s' LIMIT 0,1", playerName);
                mysql_query(query, MYSQL_IMPORT_DATA, spareid, connection);            
            }
            else
            {
                ShowPlayerDialog(spareid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login {58D3F7}Incorrect password entered.{FFFFFF}", "{FFFFFF}Your username is registered. Please login with your password below.", "Login", "Cancel");
            }

            mysql_free_result();
        }
I want password hashing/decoding in whirlpool how to change it?
Code:
//LOGIN DIALOG
    // Login dialog
    if(dialogid == DIALOG_LOGIN)
    {
		new
			loginMessage[200],
			playerName[28]
		;
		
		GetPlayerName(playerid, playerName, 24);
		format(loginMessage, sizeof(loginMessage), "{98B0CD}%s {FFFFFF}is a registered username, please login by entering your password below.", playerName);
		
        // If user presses the cancel button
        if(!response)
        {
            Kick(playerid);
        }

		// If user presses the login button
        if(response)
        {
            // Set-up variables for the query
            new query[200], escapedPass[100];

            // Find the player's name
            GetPlayerName(playerid, playerName, 24);

            // Escape the MySQL string to stop SQLi
            mysql_real_escape_string(inputtext, escapedPass);

            // Query the database
			format(query, sizeof(query), "SELECT `playerName` FROM `playerdata` WHERE playerName = '%s' AND playerPass = SHA1('%s')", playerName, escapedPass);
			mysql_query(query, MYSQL_RESULT_LOGIN, playerid, connection);
        }
    }
//REGISTER DIALOG
	// Registration dialog
	if(dialogid == DIALOG_REGISTER)
    {
        // If the user clicked the register button
        if(response)
        {
            // Check if the password is within 1 and 100 characters
            if(!strlen(inputtext) || strlen(inputtext) > 24)
            {
                // Re-show the dialog
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register {58D3F7}Password length should be between 0 and 24.{FFFFFF}", "{FFFFFF}Your username is not registered! Please register with a password below.", "Register", "Cancel");
            }
            else if(strlen(inputtext) > 0 && strlen(inputtext) < 24)
            {
                // Password was a valid length
                new 
					escapedPass[100], 
					query[200],
					playerName[28],
					Seconds = gettime(),
					myIPAddress[16]
				;
			
				GetPlayerIp(playerid, myIPAddress, sizeof(myIPAddress));
				GetPlayerName(playerid, playerName, 24);

                // Clean the string before inserting to the MySQL database
                mysql_real_escape_string(inputtext, escapedPass);
				
				format(query, sizeof(query), "INSERT INTO playerdata (playerName, playerPass, firstLogged, playerIP) VALUES('%s', SHA1('%s'), '%i', '%s')", playerName, escapedPass, Seconds, myIPAddress);
				mysql_query(query, MYSQL_RESULT_REGISTER, playerid, connection);
            }
        }
        if(!response)
        {
			ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register {58D3F7}Password length should be between 0 and 24.{FFFFFF}", "{FFFFFF}Your username is not registered! Please register with a password below.", "Register", "Cancel");
        }
    }
Reply
#2

You'll have to install the whirlpool plugin and add it in the server.cfg as well. This is an example of how to hash a password using your gamemode's vars.

PHP Code:
new hashedpass[129];
WP_Hash(hashedpasssizeof (hashedpass), escapedPass); 
hashedpass will be the hashed password.
Reply
#3

Okay but where may i add it?
There are 2 includes for login/register.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)