You are here : phpstringcrypt

crypt() - string

crypt() will return a hashed string using the
   standard Unix DES-based algorithm or
   alternative algorithms that may be available on the system.
Parameters :
  • str - The string to be hashed. Caution Using the CRYPT_BLOWFISH algorithm, will result in the str parameter being truncated to a maximum length of 72 characters.
  • salt - An optional salt string to base the hashing on. If not provided, the behaviour is defined by the algorithm implementation and can lead to unexpected results.

  • Syntax

    string crypt
        ( string $str
       [, string $salt
      ] )


    Example

    <?php$hashed_password = crypt('mypassword'); // let the salt be automatically generated/* You should pass the entire results of crypt() as the salt for comparing a   password, to avoid problems when different hashing algorithms are used. (As   it says above, standard DES-based password hashing uses a 2-character salt,   but MD5-based hashing uses 12.) */if (hash_equals($hashed_password, crypt($user_input, $hashed_password))) {   echo "Password verified!";}?>


    Output / Return Value


    Limitations


    Alternatives / See Also


    Reference