Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 297

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>crypt</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="String functions"
HREF="ref.strings.html"><LINK
REL="PREVIOUS"
TITLE="crc32"
HREF="function.crc32.html"><LINK
REL="NEXT"
TITLE="echo"
HREF="function.echo.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.crc32.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.echo.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.crypt"
></A
>crypt</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN89239"
></A
><P
>    (PHP 3, PHP 4 )</P
>crypt&nbsp;--&nbsp;One-way string encryption (hashing)</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN89242"
></A
><H2
>Description</H2
>string <B
CLASS="methodname"
>crypt</B
> ( string str [, string salt])<BR
></BR
><P
>&#13;     <B
CLASS="function"
>crypt()</B
> will return an encrypted string using the
     standard Unix <SPAN
CLASS="abbrev"
>DES</SPAN
>-based encryption algorithm or
     alternative algorithms that may be available on the system.  Arguments
     are a string to be encrypted and an optional salt string to base the
     encryption on.  See the Unix man page for your crypt function for more
     information.
    </P
><P
>&#13;     If the salt argument is not provided, one will be randomly
     generated by PHP.
    </P
><P
>&#13;     Some operating systems support more than one type of encryption.  In
     fact, sometimes the standard DES-based encryption is replaced by an
     MD5-based encryption algorithm.  The encryption type is triggered by the
     salt argument.  At install time, PHP determines the capabilities of the
     crypt function and will accept salts for other encryption types.  If no
     salt is provided, PHP will auto-generate a standard two character salt by
     default, unless the default encryption type on the system is MD5, in
     which case a random MD5-compatible salt is generated.  PHP sets a
     constant named CRYPT_SALT_LENGTH which tells you whether a regular two
     character salt applies to your system or the longer twelve character salt
     is applicable.
    </P
><P
>&#13;     If you are using the supplied salt, you should be aware that the salt is
     generated once. If you are calling this function recursively, this may
     impact both appearance and security.
    </P
><P
>&#13;     The standard DES-based encryption <B
CLASS="function"
>crypt()</B
> returns the
     salt as the first two characters of the output. It also only uses the
     first eight characters of <TT
CLASS="parameter"
><I
>str</I
></TT
>, so longer strings
     that start with the same eight characters will generate the same result
     (when the same salt is used).
    </P
><P
>&#13;     On systems where the crypt() function supports multiple
     encryption types, the following constants are set to 0 or 1
     depending on whether the given type is available:
    </P
><P
></P
><UL
><LI
><P
>&#13;       CRYPT_STD_DES - Standard DES-based encryption with a two character salt
      </P
></LI
><LI
><P
>&#13;       CRYPT_EXT_DES - Extended DES-based encryption with a nine character salt
      </P
></LI
><LI
><P
>&#13;       CRYPT_MD5 - MD5 encryption with a twelve character salt starting with
       $1$
      </P
></LI
><LI
><P
>&#13;       CRYPT_BLOWFISH - Blowfish encryption with a sixteen character salt
       starting with $2$
      </P
></LI
></UL
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
      There is no decrypt function, since <B
CLASS="function"
>crypt()</B
>
      uses a one-way algorithm.
     </P
></BLOCKQUOTE
></DIV
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN89275"
></A
><P
><B
>Example 1. <B
CLASS="function"
>crypt()</B
> examples</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
$password = crypt("My1sTpassword"); # let salt be 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 (crypt($user_input,$password) == $password) {
   echo "Password verified!";
}
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;     See also <A
HREF="function.md5.html"
><B
CLASS="function"
>md5()</B
></A
> and <A
HREF="ref.mcrypt.html"
>the
     Mcrypt extension</A
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.crc32.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.echo.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>crc32</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.strings.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>echo</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>