Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypting Passwords

What is the fastest, yet secure way to encrypt passwords (in PHP preferably), and for whichever method you choose, is it portable?

In other words, if I later migrate my website to a different server, will my passwords continue to work?

The method I am using now, as I was told, is dependent on the exact versions of the libraries installed on the server.

like image 536
UnkwnTech Avatar asked Aug 03 '08 11:08

UnkwnTech


2 Answers

If you are choosing an encryption method for your login system then speed is not your friend, Jeff had a to-and-frow with Thomas Ptacek about passwords and the conclusion was that you should use the slowest, most secure encryption method you can afford to.

From Thomas Ptacek's blog:
Speed is exactly what you don’t want in a password hash function.

Modern password schemes are attacked with incremental password crackers.

Incremental crackers don’t precalculate all possible cracked passwords. They consider each password hash individually, and they feed their dictionary through the password hash function the same way your PHP login page would. Rainbow table crackers like Ophcrack use space to attack passwords; incremental crackers like John the Ripper, Crack, and LC5 work with time: statistics and compute.

The password attack game is scored in time taken to crack password X. With rainbow tables, that time depends on how big your table needs to be and how fast you can search it. With incremental crackers, the time depends on how fast you can make the password hash function run.

The better you can optimize your password hash function, the faster your password hash function gets, the weaker your scheme is. MD5 and SHA1, even conventional block ciphers like DES, are designed to be fast. MD5, SHA1, and DES are weak password hashes. On modern CPUs, raw crypto building blocks like DES and MD5 can be bitsliced, vectorized, and parallelized to make password searches lightning fast. Game-over FPGA implementations cost only hundreds of dollars.

like image 82
Peter Coulton Avatar answered Oct 07 '22 04:10

Peter Coulton


I'm with Peter. Developer don't seem to understand passwords. We all pick (and I'm guilty of this too) MD5 or SHA1 because they are fast. Thinking about it ('cuz someone recently pointed it out to me) that doesn't make any sense. We should be picking a hashing algorithm that's stupid slow. I mean, on the scale of things, a busy site will hash passwords what? every 1/2 minute? Who cares if it take 0.8 seconds vs 0.03 seconds server wise? But that extra slowness is huge to prevent all types of common brute-forcish attacks.

From my reading, bcrypt is specifically designed for secure password hashing. It's based on blowfish, and there are many implementation.

For PHP, check out PHP Pass

For anyone doing .NET, check out BCrypt.NET

like image 42
Karl Seguin Avatar answered Oct 07 '22 03:10

Karl Seguin