Current location: Hot Scripts Forums » Programming Languages » PHP » MD5 password for registered users


MD5 password for registered users

Reply
  #1 (permalink)  
Old 10-22-06, 04:20 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
MD5 password for registered users

I want to generate a random MD5 hash for each registered user as password. I know, MD5 is one-way hash.
If user login after registration I want to compare a generated MD5 hash with MD5 hash from database.

I don't really know which is the better way to generate this MD5 hash. This formula is enough ? :

MD5 function + plain text password = md5 hash

I appreciate any suggestion.
Thanks !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-22-06, 11:55 AM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
what you should do...

is make a secret word... that only you know ( random ) you dont need to remember it... such as phebEs8e

this way if someone does access your db they cant reverse many passwords because it isnt just their password...

for instance
someone stores their password as password
then it md5s it as 5f4dcc3b5aa765d61d8327deb882cf99

This can easily be reversed with the most minor md5 reverse databases out there...

but if you do a word in front you should be pretty secure...

the code would be
PHP Code:

$md5pass md5("phebEs8e"htmlspecialchars($_POST['password])); 

Hope that helps...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-22-06, 03:20 PM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
stormshadow thank you very much !

I read this issue in Essential PHP Security (2005) - Oreilly

Quote:
Using the MD5 of a user's password is a common approach that is no longer considered particularly safe. Recent discoveries have revealed both weaknesses in the MD5 algorithm , and many MD5 databases minimize the effort required to reverse an MD5. To see an example, visit http://md5.rednoize.com/.

The best protection is to salt the user's password using a string that is unique to your application.
"phebEs8e" is a salt. But what happen is someone stole my PHP code and see the salt?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-22-06, 03:27 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
You can create a personal salt for each user. You can use for example the first the characters of his username or email address.
PHP Code:



$password 
md5(substr($username03) . $pass);

// Or

$password md5('somesalt' substr($username03) . $pass); 
Just play with it and be creative.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-23-06, 01:10 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks !
And when I change the username or password from administrator panel I need to update the hash ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-04-06, 07:41 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Nico
You can create a personal salt for each user. You can use for example the first the characters of his username or email address.
PHP Code:



$password 
md5(substr($username03) . $pass);

// Or

$password md5('somesalt' substr($username03) . $pass); 
Just play with it and be creative.
This personal salt work for me, I do something like :

PHP Code:

$username $_POST['username'];


$salt         substr($username03);
$pwdhash  md5($salt md5($password $salt)); 
Now, user login as:

user
password

And work good. But exist a problem, if user login as;

User
password

the username is case-sensitive. And : "User" and "user" generate different MD5 salt. This is not a good idea.

Exist a way to solve this problem ? I don't need case-sensitive usernames, only case-sensitive passwords.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 11-04-06, 08:54 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by zoliky
Exist a way to solve this problem ? I don't need case-sensitive usernames, only case-sensitive passwords.
Then convert the usernames to lowercase before using them:

$username = strtolower($username);
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 11-04-06, 10:06 AM
bokehman bokehman is offline
Newbie Coder
 
Join Date: Sep 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Why do you need this level of security? What are you protecting? My view is don't bother with this unless you really have something worth protecting. To be quiet honest if your siteis comprimised to this extent do you really think someone would both trying to crack a hashed password so they can log in to the site in the conventional fashion? They already have free rein to do as they please, why would they bother?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Forgot Password MD5 adubb PHP 7 07-14-06 07:54 PM
Password Problems in VB6 iceiceady Visual Basic 6 03-28-06 04:17 PM
best way to log in users, and keep them logged in nassau PHP 15 01-16-06 06:13 PM
Quick Question for you php guru's Tokahashi PHP 3 04-09-04 01:00 PM


All times are GMT -5. The time now is 06:57 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.