Jump to content


Photo

Mysql user login


  • Please log in to reply
1 reply to this topic

#1 waverider

waverider
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 21 April 2006 - 09:22 AM

Hello'
I have just swapped to a new host and a section of script no longer works. I think the problem is in the script below - using php 5.05 with the new host - 4.6 with the old one. The relevant functions are listed below the script.

The script returns 'The password you entered is incorrect' but user names and passwords in the database appear to be OK. Any assistance would be appreciated.

Thanks.



<?php

include('include_fns.php');

if ( (!isset($HTTP_POST_VARS['username'])) || (!isset($HTTP_POST_VARS['password'])) ) {
print 'You must enter your username and password to proceed';
exit;
}

$username = $HTTP_POST_VARS['username'];
$password = $HTTP_POST_VARS['password'];

if (login($username, $password)) {
$HTTP_SESSION_VARS['auth_user'] = $username;
header('Location: '.$HTTP_SERVER_VARS['HTTP_REFERER']);
}
else {
print 'The password you entered is incorrect';
exit;
}


?>
------------------------------------------------------------------------------------------
<?php
function login($username, $password)
// check username and password with db
// if yes, return true
// else return false
{
// connect to db
$conn = db_connect();
if (!$conn)
return 0;

$result = mysql_query("select * from writers
where username='$username'
and password = password('$password')");
if (!$result)
return 0;

if (mysql_num_rows($result)>0)
return 1;
else
return 0;
}

function check_auth_user()
// see if somebody is logged in and notify them if not
{
global $HTTP_SESSION_VARS;
if (isset($HTTP_SESSION_VARS['auth_user']))
return true;
else
return false;
}

function db_connect()
{
$result = @mysql_connect('localhost', 'db_user', 'password');
if (!$result)
return false;
if (!@mysql_select_db('db_name'))
return false;

return $result;

}

?>

#2 waverider

waverider
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 21 April 2006 - 12:32 PM

Problem solved - it was password encription length.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users