aidan Mon Jul 5 10:46:20 2004 EDT
Modified files:
/phpdoc/en/reference/strings/functions crypt.xml
Log:
Added second example showing htpasswd generation
http://cvs.php.net/diff.php/phpdoc/en/reference/strings/functions/crypt.xml?r1=1.3&r2=1.4&ty=u
Index: phpdoc/en/reference/strings/functions/crypt.xml
diff -u phpdoc/en/reference/strings/functions/crypt.xml:1.3
phpdoc/en/reference/strings/functions/crypt.xml:1.4
--- phpdoc/en/reference/strings/functions/crypt.xml:1.3 Mon Dec 15 11:53:50 2003
+++ phpdoc/en/reference/strings/functions/crypt.xml Mon Jul 5 10:46:20 2004
@@ -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,21 +84,37 @@
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>