PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




PHP crypt Function


Tutorials »Php »

Topic

What is crypt Function and how it is used in string?



Explanation

In PHP, this function is used for one-way string encryption or hashing.

And also it uses different algorithms like DES,MD5, BLOWFISH, based on the values of constants used along with the crypt function.

CONSTANT DESCRIPTION
CRYPT_STD_DES Standard DES-based encryption with a two character salt
CRYPT_EXT_DES Extended DES-based encryption with a nine character salt
CRYPT_MD5 MD5 encryption with a twelve character salt starting with $1$
CRYPT_BLOWFISH Blowfish encryption with a sixteen character salt starting with $2$ or $2a$
Syntax:
    crypt(str,salt)

In the above syntax "str" specifies the string to be encrypted,"salt" is the number of characters to be encoded.

Example:
    <?php
    if (CRYPT_STD_DES == 1)
    {
     echo "Standard DES: ".crypt("hiox india")."\n<br/>";
    }
    if (CRYPT_EXT_DES == 1)
    {
     echo "Extended DES: ".crypt("hiox india")."\n<br/>";
    }
    if (CRYPT_MD5 == 1)
    {
     echo "MD5: ".crypt("hiox india")."\n<br/>";
    }
    if (CRYPT_BLOWFISH == 1)
    {
     echo "Blowfish: ".crypt("hiox india");
    }
    ?>
Result:
    Standard DES: $1$uK..fl2.$MOB0iNfMOiXYhVyj9yCLX0
    MD5: $1$6D3.Vl2.$f7oVTfnVpCWi0ufek6q5x1 

In the above example, results for the supported algorithm Standard DES, MD5 is returned.





A Note

Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial. Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.

Other Links

web hosting