Problem with password function

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
Hi
I want to use password function which allow me to encrypt the password.
But the problem comes with this message:

Fatal error: Call to undefined function: password()

How can I solve this problem please ?
 
you are better to use the md5() function for encrypting passwords.

Andrew
 
There is no password() function in PHP. There is, however, an md5() function as bezmond suggest, and you should use that instead.
 
Okay, I have used md5 to encrypt the password. The piece of code that I am talking about is here:
Code:
//$name is the user name and $password represent the password
$temp2=md5('$password');
		//querythe database to see if there is a record which matches
		$query=" select count(*) from auth where
		name='$name' and  
		password='$temp2'  ";

$result=mysql_query($query);
		if(!$result)
		{
		 echo 'Cannot run query';
		 exit;
		 }

		 $count=mysql_result($result,0,0);

		 if($count>0)
		 {
	    //visitor's name and password combination are correct
		echo" you have signed in correctly";
		}

but $count is always equal to 0. So the password always is not correct. I tried displaying the password which I entered in the login form by writing
Code:
echo"$temp2";
and it was 243e61e9410a9f577d2d662c67025ee9. while it stored as: e10adc3949ba5 in the database. surely I have used md5 in MySQL also.

THANX
 
MySQL has both PASSWORD() and MD5() functions. They do not do the same things.

But the trouble, I'm guessing, is that you're using one of the MySQL functions, and expecting it to match the output from one of the PHP functions. Either you need to use md5() in PHP exclusively, or one of the above functions in MySQL exclusively. Do not mix and match.
 
swirlee, Thank you.
But What Can I do ?? How can I compare the encrypted password that has been stored in the Database with the plain password entered in the login page by the user only if I encrypt it ??
Can you tell me about some way to encryt the passwords in the database while the user use the plain password?? if this is can't be done plz tell me about another way.
:-o
 
md5 and the mysql password are one way encryption so in the mysql query when you insert it into the db use

Code:
$query = 'insert into `users` (`username`,`password`) values ("'.$_POST['username'].'",PASSWORD("'.$_POST['password'].'"))';

then to check if they entered the correct password use
Code:
$query = 'select `user_id` from `users` where `username` = "'.$_POST['username'].'" and `password` = PASSWORD("'.$_POST['password'].'") limit 1';

then do a mysql_num_rows($result) if it returns 1 the password was correct. If 0 then it was wrong.
 
Thank you Redcircle. I will try it and inform you by the resuilts.
 
Back
Top