Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 01-22-2005, 01:25 AM   PM User | #1
soren
New to the CF scene

 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
soren is an unknown quantity at this point
problem with query using password() function

I've created a simple table called users. This table contains four columns. First_Name, Last_Name, User_Name, Password. I've used the password() function when inserting a user. I have read the documentation on using other types of encryption, but it's killing me that I can't get this to work. Robert has a User_Name of "Bob" and a password of password('tomato').

===============================
HOW I ADDED BOB
insert into users values("Robert","Evans","bob",password('tomato'));

1 row added yada yada

HOW I QUERY BOB
select * from users where User_Name="bob" and password=password('tomato');

Empty Set

===============================



That exact same query is in a tutorial for a simple PHP login form, but an empty set is returned even in the command prompt using MySQL by itself, therefore the script cannot move on. Thanks for any help.

soren
soren is offline   Reply With Quote
Old 01-22-2005, 12:41 PM   PM User | #2
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf is on a distinguished road
Welcome here!

should work. make sure you entered the exact same pasword and username (same case and all).

but you realy shouldn't use the mysql PASSWORD() function cause different hashingalgortimes are used in different mysql-version, so you can't upgrade your mysql-version!which makes it completely useless for you. the reason for this is
Quote:
The PASSWORD() function is used by the authentication system in MySQL Server, you should not use it in your own applications. For that purpose, use MD5() or SHA1() instead.
from http://dev.mysql.com/doc/mysql/en/En...functions.html whare you find all info you need on sha1 --> this is what you should us (not md5)
__________________
Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html
raf is offline   Reply With Quote
Old 01-26-2005, 03:00 AM   PM User | #3
soren
New to the CF scene

 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
soren is an unknown quantity at this point
sha1 & md5 work...password() does not

Thank you for your reply and for welcoming me. I can see that I will be spending a lot of time here.

Well, it seems to work ok with sha1 and md5, but still not password(). All of this is not too big of a deal since I didn't plan on using password(). I just wanted to see it work.

However, I am working with a site that is using cPanel. They have MySQL version 4.0.22. Will sha1 and md5 still work? Can I still not worry about password()?

soren
soren is offline   Reply With Quote
Old 01-26-2005, 03:20 AM   PM User | #4
celestine
Regular Coder

 
Join Date: Oct 2003
Location: Australia
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
celestine is an unknown quantity at this point
yes. sha1 and md5 are php functions. will work with any MySQL versions, to the best of my knowledge.
__________________
Day Dream Graphics
celestine is offline   Reply With Quote
Old 01-26-2005, 03:24 AM   PM User | #5
soren
New to the CF scene

 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
soren is an unknown quantity at this point
thanks! i appreciate the the fast reply.

soren
soren is offline   Reply With Quote
Old 01-26-2005, 08:46 PM   PM User | #6
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf is on a distinguished road
Quote:
Originally Posted by soren
They have MySQL version 4.0.22. Will sha1 and md5 still work? Can I still not worry about password()?
The MySQL sha1() and md5() will work in version 4.0.22

There are identical PHP functions that will work regardless of your db-version of format. I personnaly use the PHP function to keep my code db-independent. but there is no real diffenrence between
PHP Code:
$hashed sha1($_POST['pwd']); // the PHP function
$result mysql_query("SELECT foo FROM bar WHERE user_pwd='"$hashed ."'"); 
and
PHP Code:
$result mysql_query("SELECT foo FROM bar WHERE user_pwd=sha1('"$_POST['pwd'] ."')"); // the MySQL function 
__________________
Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html
raf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:21 PM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.