Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 2nd, 2003, 10:33 PM
Registered User
 
Join Date: Dec 2003
Location: , MD, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default md5() question

Here's a question for you.
I'm trying to store encrypted passwords in a database. I do this

//From ADMIN page
$client_pw = trim($client_pw);

//SQL
$sql = " INSERT INTO CLIENTS (client_id, client_pw, client_school, client_expdate, client_fullname)
 VALUES ('".$client_id."', '".md5($client_pw)."', '".$client_school."', '".$client_expdate."', '".$client_fullname."') ;";

Resulting HASH in the DB: 3f8b243aa755cfd9

And retrieve the entered password to vailidate in this manner:

//From login page
$uname = $_POST['uname'];
$pword = $_POST['pword'];

$pword = trim($pword);
$pword = md5($pword);

//SQL
$sql = "select * from CLIENTS where client_id = '" . trim($uname).
       "' and client_pw = '".$pword."'";

HASH it tries to compare this: 3f8b243aa755cfd963741b71885955f2
to the DB entry: 3f8b243aa755cfd9

I've searched several places online and can't seem to get why there is no match. Yes I did type the same password. Most documentation on this implies that I am doing this correctly. It seems like a no-brainer. Am I missing anything?

Reply With Quote
  #2 (permalink)  
Old December 2nd, 2003, 10:56 PM
Registered User
 
Join Date: Dec 2003
Location: , MD, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok. This always happens when I post something. As soon as I post, I find the problem. The problem is not in the code, but the database field was set to varchar(16). I increased the character legnth and viola!

Reply With Quote
  #3 (permalink)  
Old December 3rd, 2003, 02:10 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Happens to the best of us. You might want to consider changing the column type from varchar to char, since all your md5 hashes should be the same length.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
md5 code !!!!! angelboy C# 2005 1 March 7th, 2007 03:25 AM
md5() in php pritz PHP How-To 1 May 17th, 2006 05:38 PM
md5() safe??? foddie PHP How-To 0 December 30th, 2005 10:25 PM
Md5 encryption rahuljain_w .NET Web Services 2 September 30th, 2005 05:03 AM
MD5() and encryption spraveens Pro PHP 2 May 20th, 2004 05:06 AM



All times are GMT -4. The time now is 08:41 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.