Sophie

Sophie

distrib > PLD > ac > amd64 > media > dist > by-pkgid > dd8ef74e7a184506d40e4328053fb785 > files > 355

php-manual-ro-20051028-1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>crypt</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Manual PHP"
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-2"></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"
>Manual PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.crc32.html"
ACCESSKEY="P"
>Înapoi</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.echo.html"
ACCESSKEY="N"
>Înainte</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.crypt"
></A
>crypt</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN112916"
></A
><P
>    (PHP 3, PHP 4 , PHP 5)</P
>crypt&nbsp;--&nbsp;One-way string encryption (hashing)</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN112919"
></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 <ABBR
CLASS="abbrev"
>DES</ABBR
>-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 <VAR
CLASS="parameter"
>str</VAR
>, 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
>Not&#227;: </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="AEN112952"
></A
><P
><B
>Exemplu 1. <B
CLASS="function"
>crypt()</B
> examples</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$password </font><font color="#007700">= </font><font color="#0000BB">crypt</font><font color="#007700">(</font><font color="#DD0000">'mypassword'</font><font color="#007700">); </font><font color="#FF8000">// let the salt be automatically generated<br /><br />/* You should pass the entire results of crypt() as the salt for comparing a<br />&nbsp;&nbsp;&nbsp;password, to avoid problems when different hashing algorithms are used. (As<br />&nbsp;&nbsp;&nbsp;it says above, standard DES-based password hashing uses a 2-character salt,<br />&nbsp;&nbsp;&nbsp;but MD5-based hashing uses 12.) */<br /></font><font color="#007700">if (</font><font color="#0000BB">crypt</font><font color="#007700">(</font><font color="#0000BB">$user_input</font><font color="#007700">, </font><font color="#0000BB">$password</font><font color="#007700">) == </font><font color="#0000BB">$password</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Password verified!"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN112956"
></A
><P
><B
>Exemplu 2. Using <B
CLASS="function"
>crypt()</B
> with htpasswd</B
></P
><P
>&#13;       To create a password for use with an apache htpasswd file, you'll need to
       use the first two letters of the password as the salt.
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">// Set the password<br /></font><font color="#0000BB">$password </font><font color="#007700">= </font><font color="#DD0000">'mypassword'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Get the hash<br /></font><font color="#0000BB">$hash </font><font color="#007700">= </font><font color="#0000BB">crypt</font><font color="#007700">(</font><font color="#0000BB">$password</font><font color="#007700">, </font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$password</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">2</font><font color="#007700">));<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></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"
>Înapoi</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Acas&#227;</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.echo.html"
ACCESSKEY="N"
>Înainte</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"
>Sus</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>echo</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>