what's the output length of PHP crypt()
?
md5()
output is 128 bits and produce a string with 32 chars, so in data base you put that in a char(32)
column, what about the crypt()
?
what's the output length of PHP crypt()
?
md5()
output is 128 bits and produce a string with 32 chars, so in data base you put that in a char(32)
column, what about the crypt()
?
read more : http://php.net/crypt
As you can see in the documentation, the '''crypt()''' function is used with various different hashing algorithms. So the length can be different and is dependent on the default hashing algorithm that can is determined by the constants described in the documentation.
Some more details:
crypt
always returns the hashed string or a string that is shorter than 13 characters and is guaranteed to differ from the salt on failure.Examples:
Lets start lightly with a simple
crypt
call and a valid two-character salt for a standard DES-based hash:If you use PHP's
crypt
and specificly MD5 (here better named: md5crypt, MD5(Unix), FreeBSD MD5, Cisco-IOS MD5; Hashcat mode 500) and an empty salt, the output length is:If on a system where PHP's
crypt
defaults to the said MD5 and it is called not specifying a salt,crypt
will generate the salt. This salt is normally 8 characters long. The output length then is:In this case, your database table column
char(32)
would either report an error on insert or truncate - depending on which database server you are using.But the MD5 example is moot, I picked it because you have it in your question, but you should not use MD5 with
crypt
(see: Md5crypt Password scrambler is no longer considered safe by author).Instead lets take a look into Blowfish hashing (
CRYPT_BLOWFISH
). It has a two digit cost parameter and always a salt length of 22 (if a shorter salt is given, it is padded with$
s):For the Blowfish crypt hash-algorithm (bcrypt, OpenBSD Blowfish; Hashcat mode 3200) there is a fixed length of 60 then.
As you can see the output length depends on the used hash-algorithm, the length of the salt and even some hash specific parameters like the cost.
If you for example opt of SHA512 with 999 999 999 rounds and a 16 byte long salt, the output length is:
This example is a little bit extreme maybe, just to show the picture.
Other
crypt
related questions:crypt() relies on the available encryption methods. The most common method for PHP is MD5 which always return 32 characters. Other methods like DES and Blowfish return strings with variable length.
You'll need to know what method the crypt() function is using in your server.