Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 22nd, 2005, 11:21 AM   #1
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Encrypting sensitive data

I'm developing a website in php with a MySql database. The website has a login page that reads the user data from localdb.logins where localdb is my database. Although I'm only developing the site to learn PHP, I like to get into good practices so I was wondering, how do you go about encrypting the username and password fields IN THE DATABASE?

Currently, here's the schema for the logins table:
mysql> describe logins;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(20) |      | PRI |         |       |
| password | varchar(20) | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql>
OpenLoop is offline   Reply With Quote
Old Aug 22nd, 2005, 11:32 AM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
You should encode the password in the database using MD5, it's easy - just insert the value with MD5( before and a ) after . The clientside should encrypt the password as well, also with MD5 (there are some nice javascripts on the internet), and send it as a form. You compare then the hashed passwords.
You could do the same with the username - but it's not necessary.

Hope this helps
Polyphemus_ is offline   Reply With Quote
Old Aug 22nd, 2005, 11:33 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Try this to encrypt the password entry of new users:

INSERT INTO logins (username,password) VALUES ('billybob',PASSWORD('mypasswd'));
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Aug 22nd, 2005, 11:46 AM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
if you want something better than MD5 php will need mcrypt support compiled in. Take a look at the mcrypt functions on the php website.

http://ca3.php.net/manual/en/ref.mcrypt.php


mcrypt supports: DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes.

it also supports some ciphers that are not free (free as in beer) as well, but i don't think you'd be using them.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Aug 22nd, 2005, 11:49 AM   #5
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
I recommend starting with MD5, when it works you can also switch to a better way of encrypting
Polyphemus_ is offline   Reply With Quote
Old Aug 22nd, 2005, 11:58 AM   #6
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 207
Rep Power: 5 BlazingWolf is on a distinguished road
MD5 is the easiest way to go for passwords. Which is all you really need to do besides mabey e-mails(don't want spammers getting your memebers e-mails) but for that you will need mycrypt which is a bit confusing when your start but one you get the hang of it it's simple.
__________________
_______________________________
BlazingWolf
BlazingWolf is offline   Reply With Quote
Old Aug 22nd, 2005, 12:01 PM   #7
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
i found mcrypt pretty easy to use.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Aug 22nd, 2005, 12:03 PM   #8
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Thanks for the help guys. For now, I'll go with the easy stuff. But if I ever go public with the website, I will use mcrypt and encrypt the password on the client-side as well.

EDIT: Just a note, PASSWORD() seems to be better than MD5() and just as easy:
MD5('cheaito') = 3aff9b940d4a940cfad131e6bbde779a
PASSWORD('cheaito') = *0DBF924D6D6CB7167F217C55F29FF9F875406960


BTW that's not my actual password.
OpenLoop is offline   Reply With Quote
Old Aug 22nd, 2005, 12:30 PM   #9
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by OpenLoop
Thanks for the help guys. For now, I'll go with the easy stuff. But if I ever go public with the website, I will use mcrypt and encrypt the password on the client-side as well.

EDIT: Just a note, PASSWORD() seems to be better than MD5() and just as easy:
MD5('cheaito') = 3aff9b940d4a940cfad131e6bbde779a
PASSWORD('cheaito') = *0DBF924D6D6CB7167F217C55F29FF9F875406960


BTW that's not my actual password.
PASSWORD looks idd better than MD5, but I'm not sure there are javascripts around on the internet to encode the password the same way.
Polyphemus_ is offline   Reply With Quote
Old Aug 22nd, 2005, 2:27 PM   #10
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Quote:
Originally Posted by Polyphemus_
PASSWORD looks idd better than MD5, but I'm not sure there are javascripts around on the internet to encode the password the same way.
I have very basic javascript knowledge so how do you encode to MD5 in javascript if i decide to do that on client side?
OpenLoop is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC