md5 is not secure for long time. If you want something more secure try CPasswordHelper which is new with yii 1.1.14. It uses crypt(3) which is better but many reports shown that it’s not as secure as we could think… The best way would be to use PBKDF2 with sha256
There’s built-in PBKDF2 support in PHP >= 5.5.0, however it says:
The PBKDF2 method can be used for hashing passwords for storage (it is NIST approved for that use). However, it should be noted that CRYPT_BLOWFISH is better suited for password storage and should be used instead via crypt(). [/i]
CodeSutra: I wouldn’t take that approach for passwords. You don’t want to encrypt the password, you want to hash the password. You never decrypt a password. You should use a one-way hashing algorithm or set of algorithms to generate a hashed password. When you want to test your password, run it through the algorithm and then check against the saved hash. If they match, you guessed correctly and you have access to whatever.
The reason MD5 and the standard SHA series by themselves are not good for password hashing algorithms is because they are very fast algorithms. People suggest using PBKDF2, bcrypt, or scrypt because those algorithms are intentionally time expensive for generating a key. If I pull your hash from the database and it is an MD5, I can feed it to John the Ripper and let it make millions of guesses per second, whereas, the other algorithms may make hundreds/sec. What is even worse, the MD5 and SHA-1 don’t use memory and can be fully parallelized, so you want to throw tons of GPUs at them to drastically improve your guess rate. The other algorithms are written to use memory, so your GPUs can’t utilize parallelization well. They have to fight over the shared memory resulting in wait time. For more info, check out Thomas Pornin’s response on “Why can’t one implement bcrypt on CUDA” on StackOverflow. He knows this stuff.
Sorry to say this, but as shness explained you in details, using any method of securing passwords, that is two-way algorithm (which means password can be read or decrypted at some point) is a complete mistake and misunderstanding of basic security concepts.
You (anyone) should ever, never be able to read password again, once it is stored in database. You should use any method, where you hash (crypt) what user has provided and you compare always hashed (crypted) strings, never unencrypted ones.
@all: Sorry for misspelling idea, but I’m neither not talking about Yii demo app itself nor about Blog example. I’m talking about Yii autogenerated app, that is done using yiic -webapp.
So, this isn’t a “small problem”, limited only to demos or examples as some suggests. This is quite “big problem”, because people are often using yiic to generate base for their new, at some point live and production, versions of their apps.
@ekerazha: Thanks for updating demo / blog app, but what we really need is to fix, what yiic is generating. Application generated this way also uses MD5, AFAIK.