]> granicus.if.org Git - apache/blob - docs/manual/misc/password_encryptions.html.en
move es and fr targets to *.utf8 extension. Update transformation
[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="../es/misc/password_encryptions.html" hreflang="es" rel="alternate" title="Español">&nbsp;es&nbsp;</a> |
28 <a href="../fr/misc/password_encryptions.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
29 </div>
30
31     <p>Notes about the password encryption formats generated and understood by
32     Apache.</p>
33   </div>
34 <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#basic">Basic Authentication</a></li>
35 <li><img alt="" src="../images/down.gif" /> <a href="#digest">Digest Authentication</a></li>
36 </ul><h3>See also</h3><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
37 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
38 <div class="section">
39 <h2><a name="basic" id="basic">Basic Authentication</a><a title="Permanent link" href="#basic" class="permalink">&para;</a></h2>
40
41     <p>There are five formats that Apache recognizes for basic-authentication
42     passwords. Note that not all formats work on every platform:</p>
43
44     <dl>
45        <dt>bcrypt</dt>
46        <dd>"$2y$" + the result of the crypt_blowfish algorithm.
47        See the APR source file
48        <a href="http://svn.apache.org/viewvc/apr/apr/trunk/crypto/crypt_blowfish.c?view=markup">crypt_blowfish.c</a>
49        for the details of the algorithm.</dd>
50
51        <dt>MD5</dt>
52        <dd>"$apr1$" + the result of an Apache-specific algorithm using an
53        iterated (1,000 times) MD5 digest of various combinations of a
54        random 32-bit salt and the password. See the APR source file
55        <a href="http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_md5.c?view=markup">apr_md5.c</a>
56        for the details of the algorithm.</dd>
57
58        <dt>SHA1</dt>
59        <dd>"{SHA}" + Base64-encoded SHA-1 digest of the password. Insecure.</dd>
60
61        <dt>CRYPT</dt>
62        <dd>Unix only. Uses the traditional Unix <code>crypt(3)</code> function
63        with a randomly-generated 32-bit salt (only 12 bits used) and the first 8
64        characters of the password. Insecure.</dd>
65
66        <dt>PLAIN TEXT (i.e. <em>unencrypted</em>)</dt>
67        <dd>Windows &amp; Netware only. Insecure.</dd>
68     </dl>
69
70     <h3>Generating values with htpasswd</h3>
71
72       <div class="example"><h3>bcrypt</h3><p><code>
73       $ htpasswd -nbB myName myPassword<br />
74       myName:$2y$05$c4WoMPo3SXsafkva.HHa6uXQZWr7oboPiC2bT/r7q1BB8I2s0BRqC
75       </code></p></div>
76
77       <div class="example"><h3>MD5</h3><p><code>
78       $ htpasswd -nbm myName myPassword<br />
79       myName:$apr1$r31.....$HqJZimcKQFAMYayBlzkrA/
80       </code></p></div>
81
82       <div class="example"><h3>SHA1</h3><p><code>
83       $ htpasswd -nbs myName myPassword<br />
84       myName:{SHA}VBPuJHI7uixaa6LQGWx4s+5GKNE=
85       </code></p></div>
86
87       <div class="example"><h3>CRYPT</h3><p><code>
88       $ htpasswd -nbd myName myPassword<br />
89       myName:rqXexS6ZhobKA
90       </code></p></div>
91
92     
93
94     <h3>Generating CRYPT and MD5 values with the OpenSSL
95              command-line program</h3>
96       
97
98       <p>OpenSSL knows the Apache-specific MD5 algorithm.</p>
99
100       <div class="example"><h3>MD5</h3><p><code>
101       $ openssl passwd -apr1 myPassword<br />
102       $apr1$qHDFfhPC$nITSVHgYbDAK1Y0acGRnY0
103       </code></p></div>
104
105       <div class="example"><h3>CRYPT</h3><p><code>
106       openssl passwd -crypt myPassword<br />
107       qQ5vTYO3c8dsU
108       </code></p></div>
109     
110
111     <h3>Validating CRYPT or MD5 passwords with the OpenSSL command
112              line program</h3>
113       
114       <p>The salt for a CRYPT password is the first two characters (converted to
115       a binary value). To validate <code>myPassword</code> against
116       <code>rqXexS6ZhobKA</code></p>
117
118       <div class="example"><h3>CRYPT</h3><p><code>
119       $ openssl passwd -crypt -salt rq myPassword<br />
120       Warning: truncating password to 8 characters<br />
121       rqXexS6ZhobKA
122       </code></p></div>
123
124       <p>Note that using <code>myPasswo</code> instead of
125       <code>myPassword</code> will produce the same result because only the
126       first 8 characters of CRYPT passwords are considered.</p>
127
128       <p>The salt for an MD5 password is between <code>$apr1$</code> and the
129       following <code>$</code> (as a Base64-encoded binary value - max 8 chars).
130       To validate <code>myPassword</code> against
131       <code>$apr1$r31.....$HqJZimcKQFAMYayBlzkrA/</code></p>
132
133       <div class="example"><h3>MD5</h3><p><code>
134       $ openssl passwd -apr1 -salt r31..... myPassword<br />
135       $apr1$r31.....$HqJZimcKQFAMYayBlzkrA/
136       </code></p></div>
137     
138
139     <h3>Database password fields for mod_dbd</h3>
140       <p>The SHA1 variant is probably the most useful format for DBD
141       authentication. Since the SHA1 and Base64 functions are commonly
142       available, other software can populate a database with encrypted passwords
143       that are usable by Apache basic authentication.</p>
144
145       <p>To create Apache SHA1-variant basic-authentication passwords in various
146       languages:</p>
147
148       <div class="example"><h3>PHP</h3><p><code>
149       '{SHA}' . base64_encode(sha1($password, TRUE))
150       </code></p></div>
151
152       <div class="example"><h3>Java</h3><p><code>
153       "{SHA}" + new sun.misc.BASE64Encoder().encode(java.security.MessageDigest.getInstance("SHA1").digest(password.getBytes()))
154       </code></p></div>
155
156       <div class="example"><h3>ColdFusion</h3><p><code>
157       "{SHA}" &amp; ToBase64(BinaryDecode(Hash(password, "SHA1"), "Hex"))
158       </code></p></div>
159
160       <div class="example"><h3>Ruby</h3><p><code>
161       require 'digest/sha1'<br />
162       require 'base64'<br />
163       '{SHA}' + Base64.encode64(Digest::SHA1.digest(password))
164       </code></p></div>
165
166       <div class="example"><h3>C or C++</h3><p><code>
167       Use the APR function: apr_sha1_base64
168       </code></p></div>
169
170       <div class="example"><h3>Python</h3><p><code>
171       import base64<br />
172       import hashlib<br />
173       "{SHA}" + format(base64.b64encode(hashlib.sha1(password).digest()))
174       </code></p></div>
175
176       <div class="example"><h3>PostgreSQL (with the contrib/pgcrypto functions
177                installed)</h3><p><code>
178         
179         '{SHA}'||encode(digest(password,'sha1'),'base64')
180       </code></p></div>
181     
182
183   </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
184 <div class="section">
185 <h2><a name="digest" id="digest">Digest Authentication</a><a title="Permanent link" href="#digest" class="permalink">&para;</a></h2>
186     <p>Apache recognizes one format for
187     digest-authentication passwords - the MD5 hash of the string
188     <code>user:realm:password</code> as a 32-character string of hexadecimal
189     digits. <code>realm</code> is the Authorization Realm argument to the
190     <code class="directive"><a href="../mod/mod_authn_core.html#authname">AuthName</a></code> directive in
191     httpd.conf.</p>
192
193     <h3>Database password fields for mod_dbd</h3>
194
195       <p>Since the MD5 function is commonly available, other software can
196       populate a database with encrypted passwords that are usable by Apache
197       digest authentication.</p>
198
199       <p>To create Apache digest-authentication passwords in various
200       languages:</p>
201
202       <div class="example"><h3>PHP</h3><p><code>
203       md5($user . ':' . $realm . ':' .$password)
204       </code></p></div>
205
206       <div class="example"><h3>Java</h3><p><code>
207       byte b[] = java.security.MessageDigest.getInstance("MD5").digest( (user + ":" + realm + ":" + password ).getBytes());<br />
208       java.math.BigInteger bi = new java.math.BigInteger(1, b);<br />
209       String s = bi.toString(16);<br />
210       while (s.length() &lt; 32)<br />
211       <span class="indent">
212         s = "0" + s;
213       </span>
214       // String s is the encrypted password
215       </code></p></div>
216
217       <div class="example"><h3>ColdFusion</h3><p><code>
218       LCase(Hash( (user &amp; ":" &amp; realm &amp; ":" &amp; password) , "MD5"))
219       </code></p></div>
220
221       <div class="example"><h3>Ruby</h3><p><code>
222       require 'digest/md5'<br />
223       Digest::MD5.hexdigest(user + ':' + realm + ':' + password)
224       </code></p></div>
225
226       <div class="example"><h3>PostgreSQL (with the contrib/pgcrypto functions installed)</h3><p><code>
227         
228         encode(digest( user || ':' || realm || ':' || password , 'md5'), 'hex')
229       </code></p></div>
230
231     
232   </div></div>
233 <div class="bottomlang">
234 <p><span>Available Languages: </span><a href="../en/misc/password_encryptions.html" title="English">&nbsp;en&nbsp;</a> |
235 <a href="../es/misc/password_encryptions.html" hreflang="es" rel="alternate" title="Español">&nbsp;es&nbsp;</a> |
236 <a href="../fr/misc/password_encryptions.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
237 </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>
238 <script type="text/javascript"><!--//--><![CDATA[//><!--
239 var comments_shortname = 'httpd';
240 var comments_identifier = 'http://httpd.apache.org/docs/trunk/misc/password_encryptions.html';
241 (function(w, d) {
242     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
243         d.write('<div id="comments_thread"><\/div>');
244         var s = d.createElement('script');
245         s.type = 'text/javascript';
246         s.async = true;
247         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
248         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
249     }
250     else {
251         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
252     }
253 })(window, document);
254 //--><!]]></script></div><div id="footer">
255 <p class="apache">Copyright 2018 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>
256 <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[//><!--
257 if (typeof(prettyPrint) !== 'undefined') {
258     prettyPrint();
259 }
260 //--><!]]></script>
261 </body></html>