PHP string crypt() Function

The crypt() is predefined PHP string function. It is used to returns a hashed string by using DES, Blowfish, or MD5 algorithms.

Following are some constants of crypt() function

  • [CRYPT_STD_DES]
  • [CRYPT_EXT_DES]
  • [CRYPT_MD5]
  • [CRYPT_BLOWFISH]
  • [CRYPT_SHA_256]
  • [CRYPT_SHA_512] etc.

Syntax:

ParameterDescriptionRequired/Optional
strSpecify the string to be hashedrequired
saltSpecify a salt stingoptional

Note: This crypt() function works with different operating System.

Example 1

Output:

Standard DES: jtigeEQ4GnSRg \

Example 2

Output:

Extended DES: _S4..javac7kJCJPxtp6 

Example 3

Output:

MD5: $1$javatpoi$/QyBQ/V7dJjcGaOq83EhL0

Note: 16 character salt starting with $5$ and the default number of rounds is 5000.

Example 4

Output:

Blowfish: $2a$09$anexamplestringforsale8idRk7z/D1GAsmHMUTi1L/e7Cjcngiy 

Example 5

Output:

SHA-256: $5$rounds=5000$anexamplestringf$cdf4KmhoNRhj0riAq6kpiYdPHGWOBEnPxtPxje3Fjm2 

Example 6

Output:

SHA-512: $6$rounds=5000$anexamplestringf$Oo0skOAdUFXkQxJpwzO05wgRHG0dhuaPBaOU/oNbGpCEKlf/7oVM5wn6AN0w2vwUgA0O24oLzGQpp1XKI6LLQ0

Example 7

Output:

SHA-512: $6$rounds=5000$anexamplestringf$Oo0skOAdUFXkQxJpwzO05wgRHG0dhuaPBaOU/oNbGpCEKlf/7oVM5wn6AN0w2vwUgA0O24oLzGQpp1XKI6LLQ0

Next TopicPHP String




Latest Courses