473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

password() and select statement

Hello
I have a problem in retrieving a row form a table that I created in
mysql db.
I insert these values in the table
'Bell',password('123').
But the problem is in my php application I cant retrieve this row
because the password that I pass dosn't match the password value in the
table.
this is the code that I wrote in my php application

$user = $_POST[username];
$pass = $_POST[password];
$q = mysql_query("SELECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pass')");

if(mysql_num_rows($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
else
{
echo
"<script>window.location.replace('administrator2.p hp')</script>";
}

so if any body has an idea about this problem please tell me about it.
thanx in advance
Shameram Sadaki

Jul 24 '06 #1
6 3262
ch******@hotmail.com wrote:
Hello
I have a problem in retrieving a row form a table that I created in
mysql db.
I insert these values in the table
'Bell',password('123').
But the problem is in my php application I cant retrieve this row
because the password that I pass dosn't match the password value in the
table.
this is the code that I wrote in my php application

$user = $_POST[username];
$pass = $_POST[password];
$q = mysql_query("SELECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pass')");

if(mysql_num_rows($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
else
{
echo
"<script>window.location.replace('administrator2.p hp')</script>";
}

so if any body has an idea about this problem please tell me about it.
thanx in advance
Shameram Sadaki
How are you putting the values into the table? What versions are the
MySQL server and the client libraries you're using in PHP?

What do you get if you do echo the password in the database and the
results of PASSWORD('$pass')?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '06 #2
*** ch******@hotmail.com escribió/wrote (24 Jul 2006 06:45:12 -0700):
$user = $_POST[username];
$pass = $_POST[password];
Unquoted strings are constants that you must define this way:

define('foo', 'bar');
echo foo; // prints bar

You probably mean:

$user = $_POST['username'];
$pass = $_POST['password'];
$q = mysql_query("SELECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pass')");
I suggest you read this article about SQL Injection:

http://en.wikipedia.org/wiki/SQL_Injection

if(mysql_num_rows($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
You're retrieving all the row data when all you need is knowing whether the
record exists. It's not good programming practice and, believe me, it's far
easier to learn the right way from the beginning than changing your habits
afterwards. I suggest you either get the primary key.
else
{
echo
"<script>window.location.replace('administrator2.p hp')</script>";
}
I presume you're aware of the fact that you must also protect
"administrator2.php" or anyway will be able to bypass the login screen.
so if any body has an idea about this problem please tell me about it.
The first test you must do is printing all strings on screen:

echo '<pre>';
var_dump($_POST);
var_dump($q);
echo '</pre>';

If SQL query looks OK, paste it in your favourite MySQL front end check if
it returns the expected result.

Also, check whether mysql_query() returned a result resouce or FALSE, don't
use the value blindly.
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Jul 24 '06 #3

Alvaro G. Vicario wrote:
*** ch******@hotmail.com escribió/wrote (24 Jul 2006 06:45:12 -0700):
$user = $_POST[username];
$pass = $_POST[password];

Unquoted strings are constants that you must define this way:

define('foo', 'bar');
echo foo; // prints bar

You probably mean:

$user = $_POST['username'];
$pass = $_POST['password'];
$q = mysql_query("SELECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pass')");

I suggest you read this article about SQL Injection:

http://en.wikipedia.org/wiki/SQL_Injection

if(mysql_num_rows($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}

You're retrieving all the row data when all you need is knowing whether the
record exists. It's not good programming practice and, believe me, it's far
easier to learn the right way from the beginning than changing your habits
afterwards. I suggest you either get the primary key.
else
{
echo
"<script>window.location.replace('administrator2.p hp')</script>";
}

I presume you're aware of the fact that you must also protect
"administrator2.php" or anyway will be able to bypass the login screen.
so if any body has an idea about this problem please tell me about it.

The first test you must do is printing all strings on screen:

echo '<pre>';
var_dump($_POST);
var_dump($q);
echo '</pre>';

If SQL query looks OK, paste it in your favourite MySQL front end check if
it returns the expected result.

Also, check whether mysql_query() returned a result resouce or FALSE, don't
use the value blindly.
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--

Actually my problem is not in quoted strings, cos if I execute this
statement I get a row:

$q = mysql_query("SELECT username FROM admin WHERE username = '$user'
");
well the real problem is that after inserting for example this record
by using the function
Password()

mysql_query("insert into admin values('$user',password('$pass'))");

I cant retrieve this record by using this statement:
$q = mysql_query("SELECT username FROM admin WHERE username = '$user'
and password= password('$pass')");

cos the password now is encrypted in the table admin, for example '123'
is in the table '773359240e'
so how can I get the record ??? Cos I tried to print the result of
mysql_query but it was empty.

Shameram Sadaki

Jul 25 '06 #4

ch******@hotmail.com wrote:
Hello
I have a problem in retrieving a row form a table that I created in
mysql db.
I insert these values in the table
'Bell',password('123').
But the problem is in my php application I cant retrieve this row
because the password that I pass dosn't match the password value in the
table.
this is the code that I wrote in my php application

$user = $_POST[username];
$pass = $_POST[password];
$q = mysql_query("SELECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pass')");

if(mysql_num_rows($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
else
{
echo
"<script>window.location.replace('administrator2.p hp')</script>";
}

so if any body has an idea about this problem please tell me about it.
thanx in advance
Shameram Sadaki
The Password Function in MySQL is only meant for the MySQL user table.

Quote from MySQL docs: "The PASSWORD() function is used by the
authentication system in MySQL Server; you should not use it in your
own applications" See
http://dev.mysql.com/doc/refman/5.0/...ction_password

You had the right idea, though. I use SHA(), and store the password in
a column with a CHAR(40) datatype.

Jul 25 '06 #5

Noodle wrote:
ch******@hotmail.com wrote:
Hello
I have a problem in retrieving a row form a table that I created in
mysql db.
I insert these values in the table
'Bell',password('123').
But the problem is in my php application I cant retrieve this row
because the password that I pass dosn't match the password value in the
table.
this is the code that I wrote in my php application

$user = $_POST[username];
$pass = $_POST[password];
$q = mysql_query("SELECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pass')");

if(mysql_num_rows($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
else
{
echo
"<script>window.location.replace('administrator2.p hp')</script>";
}

so if any body has an idea about this problem please tell me about it.
thanx in advance
Shameram Sadaki

The Password Function in MySQL is only meant for the MySQL user table.

Quote from MySQL docs: "The PASSWORD() function is used by the
authentication system in MySQL Server; you should not use it in your
own applications" See
http://dev.mysql.com/doc/refman/5.0/...ction_password

You had the right idea, though. I use SHA(), and store the password in
a column with a CHAR(40) datatype.
Thank you, it is working now. But I used md5() instead of sha() in both
the insert and the select statements.

thanx
shameram sadaki

Jul 25 '06 #6
ronverdonk
4,258 Expert 4TB
According to the MySql manual:
The SET PASSWORD statement assigns a password to an existing MySQL user account.
meaning that you only use it for MySql administration purposes.

You can use the following statement to setup your userid/password using the SHA1 (or something else). The other one shows how to retrieve it from the database:

[PHP]
The passsword create MySql code:

CREATE TABLE IF NOT EXISTS authorized_users (
userid VARCHAR(20) NOT NULL PRIMARY KEY,
passwd CHAR(40) NOT NULL);

INSERT INTO authorized_users VALUES ( 'johnny', sha1('mypw') );

The retrieve MySql code:

SELECT * FROM authorized_users WHERE userid='$userid'
AND passwd=sha1('$passwd')[/PHP]

Hope it is more clear now.

Ronald :cool:
Jul 25 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: John Victor | last post by:
In my mysql database, I've stored all the passwords using the PASSWORD() function. Now I'm running a test and need to compare the password in my php document to that saved in the database. I used...
2
by: Phil Latio | last post by:
I am trying something very simple, to pass the contents of a form (just username and password) to execute a query on MySQL table. The problem appears to be the password field. For example,...
3
by: arktikturtle | last post by:
Hi! I'm looking for a way to validate a password within PL/SQL. I want to write CREATE PROCEDURE change_password(old_password IN VARCHAR2) IS BEGIN -- check if old_password is correct... but...
5
by: Arpan | last post by:
An ASP application retrieves records from a SQL Server database. In the first page of the application, the user has to enter a password & the columns retrieved from the DB table depends upon the...
4
by: Neil Ginsberg | last post by:
I have ODBC linked tables to a SQL 7 database in an A2K database. The linked tables do not have the password stored in them, so the first time the user accesses them, they need to enter the SQL...
2
by: Matthew Wells | last post by:
Hello, I have an ADO connection object connected to an external ms access password protected database. I am trying to execute a delete statement from that object on a table in my currentdb. ...
15
by: Eugene Anthony | last post by:
Is this method of validation for password and username considered to be secured. In my previous post I was given a solution that uses command object and the values are parsed by parameters. But the...
11
by: Kevin O'Brien | last post by:
Hello, I am creating a sign on screen for my application in which I want to store the username and password in a database table. I was thinking of putting a combo box connected to the database...
9
by: Jordi Maicas | last post by:
Hello again! I've got a typical problem validating a user/pass through an access database with C#. I tried with two functions, and both tell me that the resulting string is out of context.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.