473,651 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("SE LECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pas s')");

if(mysql_num_ro ws($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
else
{
echo
"<script>window .location.repla ce('administrat or2.php')</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 3276
ch******@hotmai l.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("SE LECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pas s')");

if(mysql_num_ro ws($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
else
{
echo
"<script>window .location.repla ce('administrat or2.php')</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*******@attgl obal.net
=============== ===
Jul 24 '06 #2
*** ch******@hotmai l.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("SE LECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pas s')");
I suggest you read this article about SQL Injection:

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

if(mysql_num_ro ws($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.repla ce('administrat or2.php')</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******@hotmai l.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("SE LECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pas s')");

I suggest you read this article about SQL Injection:

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

if(mysql_num_ro ws($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.repla ce('administrat or2.php')</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("SE LECT 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("in sert into admin values('$user', password('$pass '))");

I cant retrieve this record by using this statement:
$q = mysql_query("SE LECT 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******@hotmai l.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("SE LECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pas s')");

if(mysql_num_ro ws($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
else
{
echo
"<script>window .location.repla ce('administrat or2.php')</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******@hotmai l.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("SE LECT * FROM admin WHERE username = '$user' and
password =PASSWORD('$pas s')");

if(mysql_num_ro ws($q)==0){
echo "Acces denied. User not allowed to connect.";
mysql_close();
}
else
{
echo
"<script>window .location.repla ce('administrat or2.php')</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 Recognized Expert Specialist
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_user s (
userid VARCHAR(20) NOT NULL PRIMARY KEY,
passwd CHAR(40) NOT NULL);

INSERT INTO authorized_user s VALUES ( 'johnny', sha1('mypw') );

The retrieve MySql code:

SELECT * FROM authorized_user s WHERE userid='$userid '
AND passwd=sha1('$p asswd')[/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
3699
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 the string "Select name From users Where password = PASSWORD('$testPass')" and ran mysql_query() using the string. But nothing was returned. So I decided to run a test and try to change a password from my php page using the string
2
1594
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, username: money password: penny If type in the password as penny, it won't authenticate.
3
14510
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 how? I can get the hashed value of the password from DBA_USERS, of course, but is there a way to hash old_password to see if it matches? (I wouldn't be
5
1803
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 password. For e.g. if the password entered is say, pwd1, then that user should be displayed the records of Column1 & Column2 only. If the password entered is say, pwd2, then that user should be displayed the records of Column1 & Column3 only. If...
4
18953
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 password. I am developing a process that will automatically run at night which will access those tables. I need to be able to give Access the password, as the user currently does, so that the process can run without a password prompt appearing....
2
2246
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. Seems strange I know, but I have to do it this way. My currentdb is NOT password protected. When I execute: Delete * from table1 IN "C:\abc.mdb" I get an "Invalid Password" error.
15
9722
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 solution only worked well for insert and delete, but not select. <% if Request.QueryString("Action") = 1 then username = Trim(request.form("username")) password = Trim(request.form("password")) if username <> "" and password <> "" then
11
13960
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 to pull up the usernames and then having a textbox for the user to enter their password. Can someone tell me please how to compare the contents of the textbox to the password in the database?
9
2563
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
8357
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8277
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8700
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8581
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.