• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How secure is MySQL's password() function

teknodude

Member
I've created a login system with PHP that uses md5() encryption to one-way hash the password. When the user account is created the md5 hash is stored in a field named 'password' in the MySQL table. When a user logs in the password is converted into an md5 hash and compared against the password hash in the DB table. If they match, they're let in (obviously 🙂).

The problem with this is the "one-way" nature of md5 encryption. I've used md5 in previous projects before, and it has sufficed. The problem now is that I want to be able to retrieve the password in plaintext form so that it can be e-mailed to the user as part of a 'forgotten password feature'. Obviously I don't want the password unencrypted in the DB. If I input the password in the database using something like:

INSERT INTO tableName VALUES(password($f_password));

(where $f_password is the PHP variable storing the plaintext password).

I should then be able to authenticate users and also send users their plaintext password, while storing the encrypted password in the DB table, right? Will it be secure? Is the MySQL password encryption as secure as md5?

If this won't achieve what I want, how else could I implement it?

teknodude
 
You could store _2_ versions of the password -- MD5 for user entry, and a second copy enocded using a private-key method like Blowfish. Your code will know the private key so can decrypt as needed.

Google search should turn up the main blowfish site, which has free source code (c++, etc.)
 
Originally posted by: DaveSimmons
You could store _2_ versions of the password -- MD5 for user entry, and a second copy enocded using a private-key method like Blowfish. Your code will know the private key so can decrypt as needed.

Google search should turn up the main blowfish site, which has free source code (c++, etc.)


Thanks, I'll see what I can turn up 🙂

teknodude
 
You coudl always send the user a NEW password, and update the database accordingly when the forgot their password. That's the standard way of doing it. And safest too.
 
Originally posted by: Superwormy
You coudl always send the user a NEW password, and update the database accordingly when the forgot their password. That's the standard way of doing it. And safest too.

Good idea superwormy 🙂 do you know of any PHP scripts that generate good (i.e. hard to crack, but easy to remember) passwords? I will need something like this to generate new passwords for users.

teknodude
 
What's the point of generating an easy to remember password? Best way is to generate a random password for them and let them change the password after they login. I implement that feature on all my user login systems. I wrote a random password generator passed on time, so the password it generates will unlikely to repeat itself. It's in PHP, let me know if you want to use it.
 
Originally posted by: kt
What's the point of generating an easy to remember password? Best way is to generate a random password for them and let them change the password after they login. I implement that feature on all my user login systems. I wrote a random password generator passed on time, so the password it generates will unlikely to repeat itself. It's in PHP, let me know if you want to use it.

The thing is that the users aren't allowed to change their passwords - that's all administrated by the business.

teknodude
 
Originally posted by: teknodude
Originally posted by: kt
What's the point of generating an easy to remember password? Best way is to generate a random password for them and let them change the password after they login. I implement that feature on all my user login systems. I wrote a random password generator passed on time, so the password it generates will unlikely to repeat itself. It's in PHP, let me know if you want to use it.

The thing is that the users aren't allowed to change their passwords - that's all administrated by the business.

teknodude

If that's the case, your best bet is to get the MCrypt library for PHP. It contains the code for two-way encryption. It supports many algorithms including the one someone mentioned above, Blowfish. You can get the latest distribution here.
 
Back
Top