PHP Function Crypt
php function crypt is an inbuilt function that converts a string into a hashed one. It works by using different password hashing algorithms. Unlike other message digest / hashing functions that can be used naively, producing hashes that are easily brute-forced, crypt() provides strong password hashing.
The crypt() function accepts the following argument: a string to encrypt, a salt, and an optional number of rounds. The salt is a string that will be matched with the encrypted string in order to produce a one-way hash.
By default, if the $salt parameter is not passed, PHP will generate one at install time for the system it runs on. When PHP detects that the system is based on DES, it will generate a standard two character salt; if SHA-256 is detected, a twelve character salt will be generated.
As of PHP 8.0, the crypt() function requires its $salt parameter to be passed in order to return a valid hash. If this is not done, an ArgumentCountError exception will be raised. Unless you are using a third-party API that requires crypt()-compatible hashes, it is recommended to use the password_hash() function instead which provides secure defaults and no longer raises an error for not passing the salt. It is also important to note that a decrypt method for the hash produced by crypt() is not possible, therefore password_verify() function can be used to validate such a hash.