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