e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<?xml version="1.0" encoding="ISO-8859-1"?>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<!--
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher This file is generated from xml source: DO NOT EDIT
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher -->
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<title>Password Formats - Apache HTTP Server Version 2.5</title>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<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" />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<script src="/style/scripts/prettify.min.js" type="text/javascript">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher</script>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<link href="/images/favicon.ico" rel="shortcut icon" /></head>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<body id="manual-page"><div id="page-header">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<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>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<p class="apache">Apache HTTP Server Version 2.5</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<img alt="" src="/images/feather.gif" /></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<div id="path">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<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>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<div class="toplang">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<p><span>Available Languages: </span><a href="/en/misc/password_encryptions.html" title="English">&nbsp;en&nbsp;</a> |
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<a href="/fr/misc/password_encryptions.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher</div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>Notes about the password encryption formats generated and understood by
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher Apache.</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#basic">Basic Authentication</a></li>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<li><img alt="" src="/images/down.gif" /> <a href="#digest">Digest Authentication</a></li>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<div class="section">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<h2><a name="basic" id="basic">Basic Authentication</a></h2>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>There are five formats that Apache recognizes for basic-authentication
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher passwords. Note that not all formats work on every platform:</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dl>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dt>bcrypt</dt>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dd>"$2y$" + the result of the crypt_blowfish algorithm.
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher See the APR source file
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <a href="http://svn.apache.org/viewvc/apr/apr/trunk/crypto/crypt_blowfish.c?view=markup">crypt_blowfish.c</a>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher for the details of the algorithm.</dd>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dt>MD5</dt>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dd>"$apr1$" + the result of an Apache-specific algorithm using an
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher iterated (1,000 times) MD5 digest of various combinations of a
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher random 32-bit salt and the password. See the APR source file
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <a href="http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_md5.c?view=markup">apr_md5.c</a>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher for the details of the algorithm.</dd>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dt>SHA1</dt>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dd>"{SHA}" + Base64-encoded SHA-1 digest of the password. Insecure.</dd>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dt>CRYPT</dt>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dd>Unix only. Uses the traditional Unix <code>crypt(3)</code> function
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher with a randomly-generated 32-bit salt (only 12 bits used) and the first 8
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher characters of the password. Insecure.</dd>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dt>PLAIN TEXT (i.e. <em>unencrypted</em>)</dt>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <dd>Windows &amp; Netware only. Insecure.</dd>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </dl>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <h3>Generating values with htpasswd</h3>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>bcrypt</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher $ htpasswd -nbB myName myPassword<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher myName:$2y$05$c4WoMPo3SXsafkva.HHa6uXQZWr7oboPiC2bT/r7q1BB8I2s0BRqC
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>MD5</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher $ htpasswd -nbm myName myPassword<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher myName:$apr1$r31.....$HqJZimcKQFAMYayBlzkrA/
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>SHA1</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher $ htpasswd -nbs myName myPassword<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher myName:{SHA}VBPuJHI7uixaa6LQGWx4s+5GKNE=
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>CRYPT</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher $ htpasswd -nbd myName myPassword<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher myName:rqXexS6ZhobKA
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <h3>Generating CRYPT and MD5 values with the OpenSSL
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher command-line program</h3>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>OpenSSL knows the Apache-specific MD5 algorithm.</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>MD5</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher $ openssl passwd -apr1 myPassword<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher $apr1$qHDFfhPC$nITSVHgYbDAK1Y0acGRnY0
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>CRYPT</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher openssl passwd -crypt myPassword<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher qQ5vTYO3c8dsU
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <h3>Validating CRYPT or MD5 passwords with the OpenSSL command
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher line program</h3>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>The salt for a CRYPT password is the first two characters (converted to
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher a binary value). To validate <code>myPassword</code> against
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <code>rqXexS6ZhobKA</code></p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>CRYPT</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher $ openssl passwd -crypt -salt rq myPassword<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher Warning: truncating password to 8 characters<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher rqXexS6ZhobKA
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>Note that using <code>myPasswo</code> instead of
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <code>myPassword</code> will produce the same result because only the
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher first 8 characters of CRYPT passwords are considered.</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>The salt for an MD5 password is between <code>$apr1$</code> and the
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher following <code>$</code> (as a Base64-encoded binary value - max 8 chars).
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher To validate <code>myPassword</code> against
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <code>$apr1$r31.....$HqJZimcKQFAMYayBlzkrA/</code></p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>MD5</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher $ openssl passwd -apr1 -salt r31..... myPassword<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher $apr1$r31.....$HqJZimcKQFAMYayBlzkrA/
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <h3>Database password fields for mod_dbd</h3>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>The SHA1 variant is probably the most useful format for DBD
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher authentication. Since the SHA1 and Base64 functions are commonly
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher available, other software can populate a database with encrypted passwords
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher that are usable by Apache basic authentication.</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>To create Apache SHA1-variant basic-authentication passwords in various
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher languages:</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>PHP</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher '{SHA}' . base64_encode(sha1($password, TRUE))
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>Java</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher "{SHA}" + new sun.misc.BASE64Encoder().encode(java.security.MessageDigest.getInstance("SHA1").digest(password.getBytes()))
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>ColdFusion</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher "{SHA}" &amp; ToBase64(BinaryDecode(Hash(password, "SHA1"), "Hex"))
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>Ruby</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher require 'digest/sha1'<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher require 'base64'<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher '{SHA}' + Base64.encode64(Digest::SHA1.digest(password))
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>C or C++</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher Use the APR function: apr_sha1_base64
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>PostgreSQL (with the contrib/pgcrypto functions
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher installed)</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher '{SHA}'||encode(digest(password,'sha1'),'base64')
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<div class="section">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<h2><a name="digest" id="digest">Digest Authentication</a></h2>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>Apache recognizes one format for
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher digest-authentication passwords - the MD5 hash of the string
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <code>user:realm:password</code> as a 32-character string of hexadecimal
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher digits. <code>realm</code> is the Authorization Realm argument to the
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <code class="directive"><a href="/mod/mod_authn_core.html#authname">AuthName</a></code> directive in
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher httpd.conf.</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <h3>Database password fields for mod_dbd</h3>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>Since the MD5 function is commonly available, other software can
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher populate a database with encrypted passwords that are usable by Apache
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher digest authentication.</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <p>To create Apache digest-authentication passwords in various
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher languages:</p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>PHP</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher md5($user . ':' . $realm . ':' .$password)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>Java</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher byte b[] = java.security.MessageDigest.getInstance("MD5").digest( (user + ":" + realm + ":" + password ).getBytes());<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher java.math.BigInteger bi = new java.math.BigInteger(1, b);<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher String s = bi.toString(16);<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher while (s.length() &lt; 32)<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <span class="indent">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher s = "0" + s;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </span>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher // String s is the encrypted password
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>ColdFusion</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher LCase(Hash( (user &amp; ":" &amp; realm &amp; ":" &amp; password) , "MD5"))
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>Ruby</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher require 'digest/md5'<br />
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher Digest::MD5.hexdigest(user + ':' + realm + ':' + password)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher <div class="example"><h3>PostgreSQL (with the contrib/pgcrypto functions installed)</h3><p><code>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher encode(digest( user || ':' || realm || ':' || password , 'md5'), 'hex')
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </code></p></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher </div></div>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<div class="bottomlang">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<p><span>Available Languages: </span><a href="/en/misc/password_encryptions.html" title="English">&nbsp;en&nbsp;</a> |
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<a href="/fr/misc/password_encryptions.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher</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>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<script type="text/javascript"><!--//--><![CDATA[//><!--
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallaghervar comments_shortname = 'httpd';
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallaghervar comments_identifier = 'http://httpd.apache.org/docs/trunk/misc/password_encryptions.html';
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher(function(w, d) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher d.write('<div id="comments_thread"><\/div>');
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher var s = d.createElement('script');
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher s.type = 'text/javascript';
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher s.async = true;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher else {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher})(window, document);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher//--><!]]></script></div><div id="footer">
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<p class="apache">Copyright 2015 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>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher<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[//><!--
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherif (typeof(prettyPrint) !== 'undefined') {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher prettyPrint();
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher//--><!]]></script>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher</body></html>