Password

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hey,
getting really annoyed now been trying to figure out a change password script for my uber hotel.

Here is what i've got:
PHP:
<?php
session_start();
 
$connection=mysql_connect("localhost","root","[PASSWORD]");
$db=mysql_select_db("uber",$connection);
 
 
$username = $_POST['username'];
$password = $_POST['password'];
$newpassword = $_POST['newpassword'];
$newpassword = md5($newpassword);
$confirmnewpassword = $_POST['confirmnewpassword'];
$confirmnewpassword = md5($confirmnewpassword);   
 
$result = mysql_query("SELECT password FROM users WHERE username='$username'");
if(!$result)
{
echo "The username you entered does not exist";
}
else
if(md5($password)!=mysql_result($result,0))
{
echo "You entered an incorrect password";
}
else
{
 
 
if($newpassword==$confirmnewpassword)
    $sql=mysql_query("UPDATE users SET password='$newpassword' where username='$username'");
    if($sql)
    {
    echo "Congratulations You have successfully changed your password";
    }
else
{
echo "The new password and confirm new password fields must be the same";
} 
 
}//i have added this brace //
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Let's be honest, this problem you have is a coding problem and not a Habbo problem; this thread should be posted in the Coders Paradise section.

And I have no idea what you want. You've said that you've tried to get a change password script, dumped an ugly code on us and not told us exactly what is wrong with it.
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Sorry, new to this shizz. 1 moment.

You see i want my user's to be able to change their password's via the account setting's page:
devbest-password-1.png


When i click change password after filling out a new password, this is what happens:

devbest-password-2.png


I am using the code above as the POST file.
Enough Info?
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Now I'm not sure if this is what you asked for, but I've tidied up your code and make it look a little bit more presentable.

PHP:
<?php
session_start();
 
$connection=mysql_connect("localhost","root","[PASSWORD]");
$db=mysql_select_db("uber",$connection);
 
function c( $str ) {
    return addslashes( @mysql_real_escape_string( $s, $connection ) );
}
 
if ( isset( $_POST["changepassword"] ) )
{
    $username = c( $_POST["username"] );
    $password = c( $_POST["password"] );
    $new      = md5( c( $_POST["newpassword"] ) );
    $confirm  = md5( c( $_POST["confirmnewpassword"] ) );
 
    $userQ = @mysql_query( "SELECT * FROM `users` WHERE `username` = '" . $username . "'" );
    if ( @mysql_num_rows( $userQ ) == 0 )
    {
        echo "This user does not exist.";
    }
    else
    {
        $userA = @mysql_fetch_array( $userQ );
        if ( $userA["password"] !== md5( $password ) )
        {
            echo "The password you entered is incorrect.";
        }
        else
        {
            if ( $new !== $confirm )
            {
                echo "The two new passwords you entered do not match.";
            }
            else
            {
                $change = @mysql_query( "UPDATE `users` SET `password` = '" . $new . "' WHERE `username` = '" . $username . "'" );
                if ( $change )
                {
                    echo "Your password has been changed.";
                }
                else
                {
                    echo "An error occurred with the MySQL:<br /><br />" . mysql_errno() . ": " . mysql_error();
                }
            }
        }
    }
}
else
{
    echo "Change Password<br /><br />
    <form method=\"post\">
        Username: <input type=\"text\" name=\"username\" id=\"username\" /><br />
        Current Password: <input type=\"password\" name=\"password\" id=\"password\" /><br />
        New Password: <input type=\"password\" name=\"newpassword\" id=\"newpassword\" /><br />
        Confirm New Password: <input type=\"password\" name=\"confirmnewpassword\" id=\"confirmnewpassword\" /><br /><br />
        <input type=\"submit\" name=\"changepassword\" id=\"changepassword\" value=\"Save &raquo;\" />
    </form>";
}
?>
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
When i try to change the password, it just constantly gives the error, username does not exist.
 

Users who are viewing this thread

Top