Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Help In Storing Encrypted Passwords In MySQL
soleimanian
post Nov 17 2005, 08:45 AM
Post #1


End Of Computer
Group Icon

Group: Members
Posts: 346
Joined: 1-September 04
From: .:: MARS ::.
Member No.: 28



Hi,
I need some help with storing password in mysql database or something similar.
i used to store the password in database using md5() function but there is no way to retrieve thepassword back.

Now i want to know that -
is it standard and secure way to store password?
is there any other technique to store password so i can retrive it back?

Any advice on this would be highly appreciated.
you can my quwstion in other websites
Thanks
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Nov 17 2005, 09:17 AM
Post #2


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411
myCENTs:84.36



QUOTE(soleimanian @ Nov 17 2005, 03:45 PM)
Hi,
I need some help with storing password in mysql database or something similar.
i used to store the password in database using md5() function but there is no way to retrieve thepassword back.



- But that is the whole idea behind it - NOT TO BE ABLE TO decrypt passwords, the encryption process being just one-way. In almost any given scenario, you'll find the password being encrypted and stored the first time you enter it.

From next time onwards, whenever you login, the newly entered password is again encrypted - the matched against the stored & encrytped form in the database.

For security reasons password decryption routines are never built into the system. Why do you think, 99% of the web-based services (the more secure ones) never e-mail you your password, but instead ask you to set a new one when you forget your old one. SIMPLE - because your old password cannot be decrypted and mailed to you.

Having a decryption system in place (even if it is not accessible to outsiders) opens up the doorway for a prodigal system administrator or some lesser mortal in the same office, to have a means to decrypt the passwords of other users and have some fun with 'em wink.gif

Take for example - even on Linux, a sysadmin cannot KNOW or FIND OUT what a user's password is. In case it is lost or forgotten, at best he can reset it to something that the user desires.

QUOTE
Now i want to know that -
is it standard and secure way to store password?
is there any other technique to store password so i can retrive it back?


The standard technique (one-way) is the most secure you can get, although you can use some other routine and not just a simple MD5 hash.

If you're implementing this in your own application, you can easily use MySQL AES_ENCRYPT () function to store your passwords in an encrypted form (only constraint - the storage field in mysql has to be declared Binary).

AES_ENCRYPT (Advanced Encryption Standard), however has a matching decryption function too - AES_DECRYPT - with which you can achieve what you're seeking to do... but this just serves to weaken the security mechanism - like a weak-link in the chain.

Besides, to use either of these functions, you've to use a Secret Key - sort of a master password, which will be used to encrypt the stored passwords. You need to have this handy during decryption too..or else you can never get back the original pass.

One idea, in case you want to implement this method, is to generate this secret key dynamically for each user based on some other stored data, say their name/address/phone/date of birth etc.. so each user will have a separate secret key, with which you encrypt/decrypt their passwords.

Example:
Some stored fields in the database:
============================
  • UserID    [/tab][tab]--> Some Autoincrementing ID maybe
  • First_Name    [/tab] --> Joseph
  • Last_Name[tab]--> Somebody
  • Phone    [/tab][tab]--> 123456789
  • BirthDate    [/tab]--> 10/12/1900
  • Password[tab]--> mypassword
Once the user enters all the details (including a plain text password) in the web-form, I use a routine to:
  • Take the middle two characters of the First_Name = se
  • First and last character of Last_Name = Sy
  • Last 3 digits of Phone = 789
  • First two digits of birthdate = 10
I get my secret key = seSy78910

Now I use this to call the AES_ENCRYPT function and encrypt my password and put it in the password field in the DB along with another INSERT instruction to store the rest of the data:
CODE

INSERT INTO usertable ( First_Name, Last_Name, Phone, BirthDate ) VALUES ( '...', '...', '...', '......' );
UPDATE usertable SET Password = AES_ENCRYPT ( 'mypassword', 'seSy78910' ) WHERE UserID IN ( SELECT LAST_INSERT_ID FROM usertable );



There.. that statement should update the password field in your db with the encrypted form. By issuing these two statements together I can use the LAST_INSERT_ID to get the last inserted ID of the user (depends on the auto-incrementing field) and update the password.

OR,
You can issue both statements together in a single set of instructions, in this format:
CODE

INSERT INTO usertable ( First_Name, Last_Name, Phone, BirthDate, Password ) VALUES ( '...', '...', '...', '......', AES_ENCRYPT ( 'mypassword', 'seSy78910' ) );



Since the key to encrypt is being dynamically generated using some string manipulation routine, it'll always be unique for each user and quite secure in a sense. Only thing that you'll have to safeguard is this Key Generating Mechanism. If this falls into someone else's hands he can decrypt anybody's passwords in your db. So use some pretty ingenuous and complicated routine to generate this key.

Hope this will put you on the right track..

Regards,
m^e
Go to the top of the page
 
+Quote Post
Quatrux
post Nov 17 2005, 08:39 PM
Post #3


the Q
Group Icon

Group: [HOSTED]
Posts: 1,094
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059
myCENTs:70.96



you can write your own encryption and decryption functions to encrypt/decrypt the passwords wink.gif but in my opinion the best is to use the way not to have a possibility to decrypt smile.gif
Go to the top of the page
 
+Quote Post
curare
post Nov 18 2005, 12:56 AM
Post #4


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 60
Joined: 3-November 05
From: Austria/Thailand
Member No.: 9,419



WOW, m^e, thank you for this explanation. It really sheds light on some questions I have been aksing for years.

Serious, man, this is the first time I *really* understand one-way versus two-way encryption. Someone famous said, the people which can expain complicated matters with simple words are the real geniuses.

I don't want to get into brown-nosing (remember, m^e, I used that term in my first post here 15 days ago), but this is an excellent example. Let me quote Albert Einstein, whom I admire among other things just for that, with another example: When asked how to explain the wireless telegraph, he responded, "The wireless telegraph is not difficult to understand. The ordinary telegraph is like a very long cat. You pull the tail in New York, and it meows in Los Angeles. The wireless is the same, only without the cat." biggrin.gif
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Nov 18 2005, 05:15 AM
Post #5


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411
myCENTs:84.36



Hahahaha thank you for that curare. That was simply a brilliant example. Thanks for the terrific new addition to my quotes & phrases handbook wink.gif

And since you brough the term brown-nosing up, I remember seeing an extremely hilarious rendition of it on Webster.Com..

QUOTE
Main Entry: brown·nose
Pronunciation: 'brau(n)-"nOz
Function: transitive verb
Etymology: from the implication that servility is equivalent to kissing the hinder parts of the person from whom advancement is sought

slang : to ingratiate oneself with : curry favor with
- brownnose noun
- brown·nos·er noun

Source: http://www.webster.com/cgi-bin/dictionary?va=brownnosing


What can I say except - "Very well put" wink.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. MySQL - Trouble With Bulk Insert Statements(3)
  2. MySQL Realtime Replication(4)
  3. Recover Tables From A MySQL .frm File(8)
  4. Mirror My MySQL Database To Another Mysql Server(4)
  5. How To Connect MySQL With Flash?(8)
  6. MySQL Output Database Question(18)
  7. MySQL, Multiple Tables(24)
  8. Navcat For MySQL(9)
  9. Permission Problem With Mysql Database Creation(8)
  10. Mysql And Php(15)
  11. Login System Using A Mysql Db(5)
  12. Oracle Vs. Mysql Vs. Postgresql(9)
  13. Subqueries In Mysql(1)
  14. Apache Php With Mysql On Windows [solved](9)
  15. Not Understanding Mysql(4)
  1. Mysql - So Hard(14)
  2. Mysql Problem(1)
  3. Sun Bought Mysql(6)
  4. Mysql Backup With Another Address?(4)
  5. I Have An Error With My Mysql Connection(7)
  6. Mysql And User File_priv(0)
  7. Mysql Database Management(1)
  8. Mysql Database Entry By Excel Sheets(2)
  9. Mysql On Computer(9)
  10. Any Website Provide Free Host Mysql Host?(4)
  11. Mysql Multiple Tables(1)
  12. Mysql Overhead(3)
  13. Login System(6)


 



- Lo-Fi Version Time is now: 23rd November 2008 - 06:41 PM