Added second example showing htpasswd generation

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@162679 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Aidan Lister 2004-07-05 14:46:20 +00:00
parent ab77843e77
commit 92712820bc

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.3 $ -->
<!-- $Revision: 1.4 $ -->
<!-- splitted from ./en/functions/strings.xml, last change in rev 1.2 -->
<refentry id="function.crypt">
<refnamediv>
@ -84,22 +84,38 @@
There is no decrypt function, since <function>crypt</function>
uses a one-way algorithm.
</simpara>
</note>
</note>
<example>
<title><function>crypt</function> examples</title>
<programlisting role="php">
<![CDATA[
<?php
$password = crypt("My1sTpassword"); // let salt be generated
$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.)
/* 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!";
}
?>
]]>
</programlisting>
</example>
<example>
<title>Using <function>crypt</function> with htpasswd</title>
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.
<programlisting role="php">
<![CDATA[
<?php
// Set the password
$password = 'mypassword';
// Get the hash
$hash = crypt($password, substr($password, 0, 2));
?>
]]>
</programlisting>
</example>