Connecting Tech Pros Worldwide Help | Site Map

How to use Password() in PHP? Syntax problem?

  #1  
Old September 8th, 2008, 03:55 PM
karlarneg@gmail.com
Guest
 
Posts: n/a
Hello again.
I have tried to use password() in my login-script but it did not work.

My code is:

$sql = "SELECT * FROM users";
$sql .= " WHERE username ='" .
mysql_real_escape_string($_POST['username']) . "' ";
$sql .= " AND pwd = (PASSWORD( ' " . $_POST['pwd'] . " ' )) ";

What is wrong in this?
And how should I write it?

Thanks for all help!

Karl
  #2  
Old September 8th, 2008, 04:05 PM
Sjoerd
Guest
 
Posts: n/a

re: How to use Password() in PHP? Syntax problem?


On Mon, 08 Sep 2008 07:46:10 -0700, karlarneg wrote:
Quote:
I have tried to use password() in my login-script but it did not work.
Why did it not work? Did you get an error message? What have you tried?
Quote:
$sql = "SELECT * FROM users";
$sql .= " WHERE username ='" .
mysql_real_escape_string($_POST['username']) . "' "; $sql .= " AND pwd =
(PASSWORD( ' " . $_POST['pwd'] . " ' )) ";
Maybe it is the spaces within the '' which are the problem.
  #3  
Old September 8th, 2008, 04:25 PM
Jerry Stuckle
Guest
 
Posts: n/a

re: How to use Password() in PHP? Syntax problem?


karlarneg@gmail.com wrote:
Quote:
Hello again.
I have tried to use password() in my login-script but it did not work.
>
My code is:
>
$sql = "SELECT * FROM users";
$sql .= " WHERE username ='" .
mysql_real_escape_string($_POST['username']) . "' ";
$sql .= " AND pwd = (PASSWORD( ' " . $_POST['pwd'] . " ' )) ";
>
What is wrong in this?
And how should I write it?
>
Thanks for all help!
>
Karl
>
Karl,

A bigger question is - why are you storing web users in the MySQL user
table? That should be only for MySQL users - and your website users
should never have MySQL user id's.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  #4  
Old September 8th, 2008, 05:55 PM
Jerry Stuckle
Guest
 
Posts: n/a

re: How to use Password() in PHP? Syntax problem?


Jensen Somers wrote:
Quote:
Jerry Stuckle wrote:
Quote:
>karlarneg@gmail.com wrote:
Quote:
>>Hello again.
>>I have tried to use password() in my login-script but it did not work.
>>>
>>My code is:
>>>
>>$sql = "SELECT * FROM users";
>>$sql .= " WHERE username ='" .
>>mysql_real_escape_string($_POST['username']) . "' ";
>>$sql .= " AND pwd = (PASSWORD( ' " . $_POST['pwd'] . " ' )) ";
>>>
>>What is wrong in this?
>>And how should I write it?
>>>
>>Thanks for all help!
>>>
>>Karl
>>>
>Karl,
>>
>A bigger question is - why are you storing web users in the MySQL user
>table? That should be only for MySQL users - and your website users
>should never have MySQL user id's.
>>
>>
>>
>
Who said he is using the MySQL users table? It's not because his users
table is also called users he is mixing it with the MySQL users table.
>
Yes, that's true. However, additionally, if he would have asked in the
correct newsgroup (PASSWORD is not a PHP function), he would have found
he shouldn't be using PASSWORD for encrypting user passwords.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  #5  
Old September 8th, 2008, 07:35 PM
karlarneg@gmail.com
Guest
 
Posts: n/a

re: How to use Password() in PHP? Syntax problem?


On 8 Sep, 18:46, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
Jensen Somers wrote:
Quote:
Jerry Stuckle wrote:
Quote:
karlar...@gmail.com wrote:
>Hello again.
>I have tried to use password() in my login-script but it did not work..
>
Quote:
Quote:
>My code is:
>
Quote:
Quote:
>$sql = "SELECT * FROM users";
>$sql .= " WHERE username ='" .
>mysql_real_escape_string($_POST['username']) . "' ";
>$sql .= " AND pwd = (PASSWORD( ' " . $_POST['pwd'] . " ' )) ";
>
Quote:
Quote:
>What is wrong in this?
>And how should I write it?
>
Quote:
Quote:
>Thanks for all help!
>
Quote:
Quote:
>Karl
>
Quote:
Quote:
Karl,
>
Quote:
Quote:
A bigger question is - why are you storing web users in the MySQL user
table? *That should be only for MySQL users - and your website users
should never have MySQL user id's.
>
Quote:
Who said he is using the MySQL users table? It's not because his users
table is also called users he is mixing it with the MySQL users table.
>
Yes, that's true. *However, additionally, if he would have asked in the
correct newsgroup (PASSWORD is not a PHP function), he would have found
he shouldn't be using PASSWORD for encrypting user passwords.
>
I use md5 and sha1 instead of password(); Now I have the result I was
looking for:)

Now I have to find out how I can do the input sensitive!
I have to control that uppercase and lowercase are exactly written
into the field as it is stored in the database!

Thanks for all help and advice!

Karl
  #6  
Old September 8th, 2008, 09:45 PM
Michael Fesser
Guest
 
Posts: n/a

re: How to use Password() in PHP? Syntax problem?


..oO(karlarneg@gmail.com)
Quote:
>I have tried to use password() in my login-script but it did not work.
>
>My code is:
>
>$sql = "SELECT * FROM users";
>$sql .= " WHERE username ='" .
>mysql_real_escape_string($_POST['username']) . "' ";
>$sql .= " AND pwd = (PASSWORD( ' " . $_POST['pwd'] . " ' )) ";
The $_POST['pwd'] variable has to be escaped as well! You should also
consider using sprintf() or prepared statements to create the query,
e.g.

$sql = "
SELECT ... -- you should explicitly list the columns to retrieve
FROM users
WHERE username = '%s'
AND pwd = PASSWORD('%s')
";
$query = sprintf($sql,
mysql_real_escape_string($_POST['username']),
mysql_real_escape_string($_POST['pwd'])
);

Micha
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql database in UTF8, PHP shows latin1 (iso-8859-1) alex answers 39 June 27th, 2008 05:15 PM
php extensions and windows... specifically extension_dir Chris Paul answers 3 December 5th, 2005 12:45 AM
CLI0119E from "call sqlj_install_jar()" in PHP Larry Menard answers 13 November 30th, 2005 09:05 PM
Cannot use mail() in IE, only works in a debugger--help baustin75@gmail.com answers 8 October 5th, 2005 06:15 PM