Tuesday, 28 August 2018

The PHP login form does not connect to a user with the correct credentials

I have a php form that when the user submits with incorrect credentials gets appropriate error messages but when using correct credentials does not get login success message just the same incorrect credentials message. I have tried with both hashing password and without no luck. Here is my login function code:

function login($username, $password) {

$host = 'localhost';
$user = 'jamaixan_bobsled';
$pass = 'v67fvg7gk_&g';
$db = 'db_for_site_67';
mysql_connect($host, $user, $pass);
mysql_select_db($db);
$connected = mysql_select_db($db);

$user_id = user_id_from_username ($username);
$password = md5($password);

return(mysql_result(mysql_query("SELECT COUNT(`id_user`) FROM `table_of_users` WHERE 

`email_user` = `$username` AND `password_user` = `$password`") , 0) == 1) ? $user_id : `false`;
    }


I recommend you to use PDOs, a more secure way to handle DB request. mysql_* functions are deprecated.

0 comments:

Post a Comment