Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it secure to store a PHP crypt() result in the db?

For example with blowfish it returns something like:

$2a$12$DEzG.CRsHpxpTOAHooQ.wuR6Xe9h6PxFPhOcOvf.lqDNw1TVYVnEO

That contains info about the type of hashing alg and it contains the salt. A lot of resources say to just store this value in the db and it will be secure. But couldn't someone just test a common list of passwords against these values to crack some of them?

like image 820
Ryan Avatar asked Jun 08 '12 10:06

Ryan


People also ask

Is crypt secure?

crypt is considered to be cryptographically far too weak to withstand brute-force attacks by modern computing systems (Linux systems generally ship with GNU Privacy Guard which is considered to be reasonably secure by modern standards)

What is crypt () in PHP?

Definition and Usage. The crypt() function returns a hashed string using DES, Blowfish, or MD5 algorithms. This function behaves different on different operating systems. PHP checks what algorithms are available and what algorithms to use when it is installed. The salt parameter is optional.

How are passwords stored securely?

Hashing and encryption both provide ways to keep sensitive data safe. However, in almost all circumstances, passwords should be hashed, NOT encrypted. Hashing is a one-way function (i.e., it is impossible to "decrypt" a hash and obtain the original plaintext value). Hashing is appropriate for password validation.


2 Answers

The security of password hashing does not come from information being secret. You have already discarded the actual secret, namely the password that is the basis for the hash value. The remaining hash is simply a sort of fingerprint of this original data. The security comes from the fact that it is not possible to derive the original data from the hash. The only possibility is to try all possible passwords and see which produces the same hash. The security here comes from the fact that this is computationally very expensive and unlikely to succeed in a useful amount of time.

The salt is only introduced to prevent somebody from using an already precomputed set of known hashed passwords, forcing an attacker to actually rehash all possible passwords with the unique salt. The salt itself is not secret, neither is the hashing algorithm.

In short: yes, that value is absolutely safe to store in a database.

like image 194
deceze Avatar answered Sep 20 '22 09:09

deceze


The hash generated by crypt() is specifically intended to be stored. No matter what your password hashing scheme is, if somebody gets hold of your database contents, they will be able to brute-force your passwords, and you don't have the option of not storing password hashes at all. The algorithms applied by crypt() are specifically selected because they take significant time to calculate the hash; this is not apparent when you only test one password, but brute-forcing thousands of passwords becomes impractically slow.

like image 21
lanzz Avatar answered Sep 19 '22 09:09

lanzz