Solved

Encrypt and decrypt passwords in php

Posted on 2016-09-22
7
16 Views
Last Modified: 2016-09-22
What is the best way to encrypt a password to store in mysql databese? I mean in both ways ( encryption and decryption)?

I read about md5 is not enough since it's easly be decrypted....

What do you suggest i should do to hash passwords and decrypt it?
0
Comment
Question by:Braveheartli
7 Comments
 
LVL 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
The best way? The best way is not to store passwords. Store a salted hash instead.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Hashes like MD5 and SHA are one-way functions.  MD5 takes some serious computing power to break it.  SHA takes more.  Where there is no financial reward for 'breaking' the passwords, MD5 is still used because it is good enough.

This page addresses what PHP provides: http://php.net/manual/en/faq.passwords.php  And more info: http://phpsec.org/articles/2005/password-hashing.html
0
 
LVL 20

Assisted Solution

by:Russ Suter
Russ Suter earned 333 total points
Comment Utility
There are 3 ways to handle credential validation: They are (in order of best to worst solution)

1. Store a hashed value using a strong hashing algorithm like SHA-256. When a user provides his/her credentials, hash the input and compare the hashes. If they match then you can authenticate the user. This is the best practice and should be used in 99% of cases.

2. Store the password in an encrypted format. When a user provides credentials, decrypt the stored value and compare it to the plain-text input. Use this only when necessary for some reason. If you have a requirement that passwords are recoverable this is the solution.

3. Store the password in plain-text. Use this method only if you're a complete idiot.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 34

Assisted Solution

by:gr8gonzo
gr8gonzo earned 167 total points
Comment Utility
MD5 cannot be decrypted. Hashes are one-way functions. MD5 is considered weaker than other hashes, and you have databases out there that try to "decrypt" hashes by simply storing billions of varieties of hashes so you can find a matching one. Salting the hash refers to adding a known prefix like "Braveheartli" to the beginning of every string before it is hashed. That way, even if you do find a matching hash in some database out there, it won't work once the salting takes place because the salting makes the string different.

You should never depend on decrypting passwords. Any kind of decryption is weak. As ste5an said, use a salted hash. You can use salted MD5 or SHA1 or something stronger, but it's generally your best way to go.
0
 
LVL 1

Author Comment

by:Braveheartli
Comment Utility
Thank you all,
So i should use salted hash and to store passwords, when i check the passwords i actually check the hash version of the password to compare if it is valid or not?

Right?
0
 
LVL 20

Accepted Solution

by:
Russ Suter earned 333 total points
Comment Utility
To clarify what you wrote above. You don't store the passwords anywhere. You use a hashing function with the password as your input and store the resulting hashed value. You then hash any user input in the same manner and compare the resulting hashes to determine if there is a match. The only known attack on a hash is brute force. MD5 has been around a long time and is one of the weaker hashing algorithms. SHA-256 is the preferred method these days. Regardless of which hashing algorithm you use it is guaranteed to be more secure than storing encrypted data.
0
 
LVL 1

Author Closing Comment

by:Braveheartli
Comment Utility
Thank you all
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now