The crypt() function returns a string encrypted using DES, Blowfish, or MD5 algorithms.
This function behaves different on different operating systems, some operating systems supports more than one type of encryption. PHP checks what algorithms are available and what algorithms to use when it is installed.
The exact algorithm depends on the format and length of the salt parameter. Salts help make the encryption more secure by increasing the number of encrypted strings that can be generated for one specific string with one specific encryption method.
There are some constants that are used together with the crypt() function. The value of these constants are set by PHP when it is installed.
Note: There is no decrypt function. The crypt() function uses a one-way algorithm.
|str||Required. Specifies the string to be encoded|
|salt||Optional. A string used to increase the number of characters encoded, to make the encoding more secure. If the salt argument is not provided, one will be randomly generated by PHP each time you call this function.|
|Return Value:||Returns the encoded string or a string that is shorter than 13 characters and is guaranteed to differ from the salt on failure|
|Changelog:||$2x$ and $2y$ Blowfish modes wad added in PHP 5.3.7 to deal with
potential high-bit attacks.
The constants SHA-256 and SHA-512 was added in PHP 5.3.2
As of PHP 5.3.0, PHP contains its own implementation for the MD5 crypt, Standard DES, Extended DES and the Blowfish algorithms and will use that if the system lacks of support for one or more of the algorithms.
In this example we will test the different algorithms:
The output of the code above could be (depending on the operating system):
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.