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