]> granicus.if.org Git - apache/blob - docs/manual/misc/password_encryptions.html.en
Documentation rebuild after recent commits
[apache] / docs / manual / misc / password_encryptions.html.en
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
4 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
5 <!--
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7               This file is generated from xml source: DO NOT EDIT
8         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9       -->
10 <title>Password Formats - Apache HTTP Server Version 2.5</title>
11 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
12 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
13 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
14 <script src="../style/scripts/prettify.min.js" type="text/javascript">
15 </script>
16
17 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
18 <body id="manual-page"><div id="page-header">
19 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
20 <p class="apache">Apache HTTP Server Version 2.5</p>
21 <img alt="" src="../images/feather.png" /></div>
22 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
23 <div id="path">
24 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Miscellaneous Documentation</a></div><div id="page-content"><div id="preamble"><h1>Password Formats</h1>
25 <div class="toplang">
26 <p><span>Available Languages: </span><a href="../en/misc/password_encryptions.html" title="English">&nbsp;en&nbsp;</a> |
27 <a href="../fr/misc/password_encryptions.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
28 </div>
29
30     <p>Notes about the password encryption formats generated and understood by
31     Apache.</p>
32   </div>
33 <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#basic">Basic Authentication</a></li>
34 <li><img alt="" src="../images/down.gif" /> <a href="#digest">Digest Authentication</a></li>
35 </ul><h3>See also</h3><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
36 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
37 <div class="section">
38 <h2><a name="basic" id="basic">Basic Authentication</a></h2>
39
40     <p>There are five formats that Apache recognizes for basic-authentication
41     passwords. Note that not all formats work on every platform:</p>
42
43     <dl>
44        <dt>bcrypt</dt>
45        <dd>"$2y$" + the result of the crypt_blowfish algorithm.
46        See the APR source file
47        <a href="http://svn.apache.org/viewvc/apr/apr/trunk/crypto/crypt_blowfish.c?view=markup">crypt_blowfish.c</a>
48        for the details of the algorithm.</dd>
49
50        <dt>MD5</dt>
51        <dd>"$apr1$" + the result of an Apache-specific algorithm using an
52        iterated (1,000 times) MD5 digest of various combinations of a
53        random 32-bit salt and the password. See the APR source file
54        <a href="http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_md5.c?view=markup">apr_md5.c</a>
55        for the details of the algorithm.</dd>
56
57        <dt>SHA1</dt>
58        <dd>"{SHA}" + Base64-encoded SHA-1 digest of the password. Insecure.</dd>
59
60        <dt>CRYPT</dt>
61        <dd>Unix only. Uses the traditional Unix <code>crypt(3)</code> function
62        with a randomly-generated 32-bit salt (only 12 bits used) and the first 8
63        characters of the password. Insecure.</dd>
64
65        <dt>PLAIN TEXT (i.e. <em>unencrypted</em>)</dt>
66        <dd>Windows &amp; Netware only. Insecure.</dd>
67     </dl>
68
69     <h3>Generating values with htpasswd</h3>
70
71       <div class="example"><h3>bcrypt</h3><p><code>
72       $ htpasswd -nbB myName myPassword<br />
73       myName:$2y$05$c4WoMPo3SXsafkva.HHa6uXQZWr7oboPiC2bT/r7q1BB8I2s0BRqC
74       </code></p></div>
75
76       <div class="example"><h3>MD5</h3><p><code>
77       $ htpasswd -nbm myName myPassword<br />
78       myName:$apr1$r31.....$HqJZimcKQFAMYayBlzkrA/
79       </code></p></div>
80
81       <div class="example"><h3>SHA1</h3><p><code>
82       $ htpasswd -nbs myName myPassword<br />
83       myName:{SHA}VBPuJHI7uixaa6LQGWx4s+5GKNE=
84       </code></p></div>
85
86       <div class="example"><h3>CRYPT</h3><p><code>
87       $ htpasswd -nbd myName myPassword<br />
88       myName:rqXexS6ZhobKA
89       </code></p></div>
90
91     
92
93     <h3>Generating CRYPT and MD5 values with the OpenSSL
94              command-line program</h3>
95       
96
97       <p>OpenSSL knows the Apache-specific MD5 algorithm.</p>
98
99       <div class="example"><h3>MD5</h3><p><code>
100       $ openssl passwd -apr1 myPassword<br />
101       $apr1$qHDFfhPC$nITSVHgYbDAK1Y0acGRnY0
102       </code></p></div>
103
104       <div class="example"><h3>CRYPT</h3><p><code>
105       openssl passwd -crypt myPassword<br />
106       qQ5vTYO3c8dsU
107       </code></p></div>
108     
109
110     <h3>Validating CRYPT or MD5 passwords with the OpenSSL command
111              line program</h3>
112       
113       <p>The salt for a CRYPT password is the first two characters (converted to
114       a binary value). To validate <code>myPassword</code> against
115       <code>rqXexS6ZhobKA</code></p>
116
117       <div class="example"><h3>CRYPT</h3><p><code>
118       $ openssl passwd -crypt -salt rq myPassword<br />
119       Warning: truncating password to 8 characters<br />
120       rqXexS6ZhobKA
121       </code></p></div>
122
123       <p>Note that using <code>myPasswo</code> instead of
124       <code>myPassword</code> will produce the same result because only the
125       first 8 characters of CRYPT passwords are considered.</p>
126
127       <p>The salt for an MD5 password is between <code>$apr1$</code> and the
128       following <code>$</code> (as a Base64-encoded binary value - max 8 chars).
129       To validate <code>myPassword</code> against
130       <code>$apr1$r31.....$HqJZimcKQFAMYayBlzkrA/</code></p>
131
132       <div class="example"><h3>MD5</h3><p><code>
133       $ openssl passwd -apr1 -salt r31..... myPassword<br />
134       $apr1$r31.....$HqJZimcKQFAMYayBlzkrA/
135       </code></p></div>
136     
137
138     <h3>Database password fields for mod_dbd</h3>
139       <p>The SHA1 variant is probably the most useful format for DBD
140       authentication. Since the SHA1 and Base64 functions are commonly
141       available, other software can populate a database with encrypted passwords
142       that are usable by Apache basic authentication.</p>
143
144       <p>To create Apache SHA1-variant basic-authentication passwords in various
145       languages:</p>
146
147       <div class="example"><h3>PHP</h3><p><code>
148       '{SHA}' . base64_encode(sha1($password, TRUE))
149       </code></p></div>
150
151       <div class="example"><h3>Java</h3><p><code>
152       "{SHA}" + new sun.misc.BASE64Encoder().encode(java.security.MessageDigest.getInstance("SHA1").digest(password.getBytes()))
153       </code></p></div>
154
155       <div class="example"><h3>ColdFusion</h3><p><code>
156       "{SHA}" &amp; ToBase64(BinaryDecode(Hash(password, "SHA1"), "Hex"))
157       </code></p></div>
158
159       <div class="example"><h3>Ruby</h3><p><code>
160       require 'digest/sha1'<br />
161       require 'base64'<br />
162       '{SHA}' + Base64.encode64(Digest::SHA1.digest(password))
163       </code></p></div>
164
165       <div class="example"><h3>C or C++</h3><p><code>
166       Use the APR function: apr_sha1_base64
167       </code></p></div>
168
169       <div class="example"><h3>Python</h3><p><code>
170       import base64<br />
171       import hashlib<br />
172       "{SHA}" + format(base64.b64encode(hashlib.sha1(password).digest()))
173       </code></p></div>
174
175       <div class="example"><h3>PostgreSQL (with the contrib/pgcrypto functions
176                installed)</h3><p><code>
177         
178         '{SHA}'||encode(digest(password,'sha1'),'base64')
179       </code></p></div>
180     
181
182   </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
183 <div class="section">
184 <h2><a name="digest" id="digest">Digest Authentication</a></h2>
185     <p>Apache recognizes one format for
186     digest-authentication passwords - the MD5 hash of the string
187     <code>user:realm:password</code> as a 32-character string of hexadecimal
188     digits. <code>realm</code> is the Authorization Realm argument to the
189     <code class="directive"><a href="../mod/mod_authn_core.html#authname">AuthName</a></code> directive in
190     httpd.conf.</p>
191
192     <h3>Database password fields for mod_dbd</h3>
193
194       <p>Since the MD5 function is commonly available, other software can
195       populate a database with encrypted passwords that are usable by Apache
196       digest authentication.</p>
197
198       <p>To create Apache digest-authentication passwords in various
199       languages:</p>
200
201       <div class="example"><h3>PHP</h3><p><code>
202       md5($user . ':' . $realm . ':' .$password)
203       </code></p></div>
204
205       <div class="example"><h3>Java</h3><p><code>
206       byte b[] = java.security.MessageDigest.getInstance("MD5").digest( (user + ":" + realm + ":" + password ).getBytes());<br />
207       java.math.BigInteger bi = new java.math.BigInteger(1, b);<br />
208       String s = bi.toString(16);<br />
209       while (s.length() &lt; 32)<br />
210       <span class="indent">
211         s = "0" + s;
212       </span>
213       // String s is the encrypted password
214       </code></p></div>
215
216       <div class="example"><h3>ColdFusion</h3><p><code>
217       LCase(Hash( (user &amp; ":" &amp; realm &amp; ":" &amp; password) , "MD5"))
218       </code></p></div>
219
220       <div class="example"><h3>Ruby</h3><p><code>
221       require 'digest/md5'<br />
222       Digest::MD5.hexdigest(user + ':' + realm + ':' + password)
223       </code></p></div>
224
225       <div class="example"><h3>PostgreSQL (with the contrib/pgcrypto functions installed)</h3><p><code>
226         
227         encode(digest( user || ':' || realm || ':' || password , 'md5'), 'hex')
228       </code></p></div>
229
230     
231   </div></div>
232 <div class="bottomlang">
233 <p><span>Available Languages: </span><a href="../en/misc/password_encryptions.html" title="English">&nbsp;en&nbsp;</a> |
234 <a href="../fr/misc/password_encryptions.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
235 </div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
236 <script type="text/javascript"><!--//--><![CDATA[//><!--
237 var comments_shortname = 'httpd';
238 var comments_identifier = 'http://httpd.apache.org/docs/trunk/misc/password_encryptions.html';
239 (function(w, d) {
240     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
241         d.write('<div id="comments_thread"><\/div>');
242         var s = d.createElement('script');
243         s.type = 'text/javascript';
244         s.async = true;
245         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
246         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
247     }
248     else {
249         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
250     }
251 })(window, document);
252 //--><!]]></script></div><div id="footer">
253 <p class="apache">Copyright 2016 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
254 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
255 if (typeof(prettyPrint) !== 'undefined') {
256     prettyPrint();
257 }
258 //--><!]]></script>
259 </body></html>