FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
PASSWORD() not working
Message  

Reply with quote
Post PASSWORD() not working 
Hi all Very Happy ,
I looked through the tutorials for info about this, but I couldn't find exactly what I was looking for.

I'm using PASSWORD() to encrypt a password.  It uploads to the database in an encrypted form, but when I try to call confirm a password at login, I can't get the two to match.  I know it's a PASSWORD issue, because if i get rid of it and submit info without any kind of encryption, it works.

Here's what my abbreviated code looks like:
Code:

//register script
          $query = "INSERT INTO users (username, password) VALUES (PASSWORD('$password'))";
//login script
           $query = "SELECT info FROM  users WHERE (username = '$u' AND password = PASSWORD('$p'))"



Any help is greatly appreciated!

View user's profile Send private message Visit poster's website AIM Address

Reply with quote
Post  
Try this in the login part:
Code:
$query = "SELECT info FROM users WHERE (username = '$u' AND password = '".PASSWORD($p)."'";
Furthermore, you could simply use the md5 function to encrypt. It's a sufficiently good one-way hashing algorihtm. I never rely on security by obscurity.

View user's profile Send private message Visit poster's website MSN Messenger

Reply with quote
Post  
that returned this error:
Fatal error: Call to undefined function: password() in /var/www/html/login.php on line 26

i'm using PHP 4.3, this should work right?

View user's profile Send private message Visit poster's website AIM Address

Reply with quote
Post  
I'd missed a close bracket. It should be
Code:
$query = "SELECT info FROM users WHERE (username = '$u' AND password = '".PASSWORD($p)."')";

The version of PHP shouldn't matter. If this doesn't work then could you please say what errors you're getting and what the original error was. If the PASSWORD() function is short, then posting that could help too.

View user's profile Send private message Visit poster's website MSN Messenger

Reply with quote
Post  
I caught the close bracket.

the original error was just my code echoing that the passwords don't match.  I'm still getting this error, resulting from the '".PASSWORD('p')."' change:

Fatal error: Call to undefined function: password() in /var/www/html/login.php on line 26

I'm not sure what you mean by "if the PASSWORD() function is short".

View user's profile Send private message Visit poster's website AIM Address

Reply with quote
Post  
You shouldn't need the single quotes in the functions parameter. An undefined function error means that it can't find the function. Remember that the function name is case sensitive, double check that you included the file if it is in anaother file. I can't think of what else there is. Maybe you've missed a { or } somewhere which causes errors. You could try making a backup of the file and using md5() instead of PASSWORD().

You use $query = "INSERT INTO users (username, password) VALUES (PASSWORD('$password'))"; to store the info, should it be ...VALUES ('something', PASSWORD($password)...? Check your database and see if the details are appearing where they should be.

One more possability is if PASSWORD can ever create special characters like / \ ' " ( ) &. If it can, then some built in escaping might be taking place which changes the table entries. You'd better debug. When you're loggin in, try something like this:
Code:
echo "entered password: ".$p."<br />";
echo "which when encrypted is: ".$PASSWORD($p)."<br />";

$query = "SELECT password FROM users WHERE (username = '$u')"
$p = mysql_result($query,0);
echo "<br />DB encrypted pass: ".$p."<br />";
I think you can figure out where that goes. Maybe that'll help see what's wrong.

I'd say long is more than 10-15 lines.

View user's profile Send private message Visit poster's website MSN Messenger

Reply with quote
Post  
The md5() function is a great way to do this. For more information on it, Visit php.net and get the manual.

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com