-1

I have read that using password_hash() is one of the best way of generating passwords using php. I have ran some tests and this function is really hard on the CPU. Is it worth it vs a salted sha1() method?

I don't mind using it, but there might be a login every 10 seconds or so I'm worried it will slow the server down.

I set up a loop to generate 1000 password_hash() values and the server timed out after 30 seconds. In comparison I generated 1000 salted sha1() passwords and it was instant.

Is the performance hit worth it?

11
  • 4
    Slow password hashing is a good thing. Also SHA1 is broken and obsolete and has been for a while now. You shouldn't even be considering it.
    – John Conde
    May 28, 2015 at 15:15
  • 2
    You don't use password_hash() for logging in; you use it for new passwords/password changes..... do you have a new password/password change every 10 seconds, or simply a login every 10 seconds?
    – Mark Baker
    May 28, 2015 at 15:16
  • 2
    Totes worth it. You really shouldn't use your own salts on password hashes and you really should use PHP's built-in functions to handle password security. May 28, 2015 at 15:17
  • 1
    No, when a user logs in, you use password_verify() to compare their entered password against the hash that you have stored on the database
    – Mark Baker
    May 28, 2015 at 15:22
  • 1
    Simply hash it, and you'll get a different value, because every generated hash has a unique salt.... you don't simply create a new hash and compare, you need to be able to use the same salt that was generated for the original hash when you verify
    – Mark Baker
    May 28, 2015 at 15:37

1 Answer 1

4

The point of protecting passwords in the database is to give you some time after a database compromise to notice you've been compromised, lock accounts, and issue notice to your users that they need to change passwords if they re-used them elsewhere.

Simple hashing such as salted-SHA1 barely fulfills this purpose any more. With hardware-accelerated brute-force it is feasible for an attacker to obtain a lot of the passwords before you've had much chance to do anything about it.

“Worth it” always varies for every application and its threat model, and there are certainly other approaches to handling passwords/authentication that can be justified, but approaches like password_hash are considered the baseline standard practice for web applications, something that today you have to justify not using.

And because users do—alas—re-use passwords across sites, skimping on hashing means that in the event of database compromise it is not just your own site's security that is at risk. So even if your service contains nothing especially sensitive, you have some degree of responsibility for others.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.