Password Schemes
================

Password scheme means the format in which the password is stored in <password
databases> [PasswordDatabase.txt]. The most commonly used password schemes are:

 * *PLAIN*: Password is in plaintext.
 * *CRYPT*: Traditional DES-crypted password in '/etc/passwd' (e.g. "pass" =
   'vpvKh.SaNbR6s')
    * Dovecot uses libc's 'crypt()' function, which means that CRYPT is usually
      able to decrypt also MD5-CRYPT and possibly also other password schemes.
 * *MD5-CRYPT*: MD5 based salted password hash nowadays commonly used in
   '/etc/shadow'. (e.g. "pass" = '$1$ozdpg0V0$0fb643pVsPtHVPX8mCZYW/')
    * *MD5*: Alias for MD5-CRYPT. Dovecot versions earlier than v1.0.rc16 need
      to use this instead of MD5-CRYPT. This name is deprecated because
      MD5-CRYPT isn't an actual MD5 hash.
 * *PLAIN-MD5*: An actual MD5 hash of the password. (e.g. "pass" =
   '1a1dc91c907325c69271ddf0c944bc72')

Password databases have a default password scheme:

 * <SQL> [AuthDatabase.SQL.txt]: See 'default_pass_scheme' setting in
   'dovecot-sql.conf'
 * <LDAP> [AuthDatabase.LDAP.txt]: See 'default_pass_scheme' setting in
   'dovecot-ldap.conf'
 * <PasswdFile> [AuthDatabase.PasswdFile.txt]: CRYPT is used by default, v1.1+
   allows changing with 'scheme' parameter in passdb args.
 * <Passwd> [AuthDatabase.Passwd.txt], <Shadow> [PasswordDatabase.Shadow.txt],
   <VPopMail> [AuthDatabase.VPopMail.txt]: CRYPT is used by default and can't
   be changed currently.
 * <PAM> [PasswordDatabase.PAM.txt], <BSDAuth> [PasswordDatabase.BSDAuth.txt],
   <CheckPassword> [PasswordDatabase.CheckPassword.txt]: Dovecot never even
   sees the password with these databases, so Dovecot has nothing to do with
   what password scheme is used.

The password scheme can be overridden for each password by prefixing it with
{SCHEME}, for example:'{PLAIN}pass'.

Dovecot contains a 'dovecotpw' utility which can be used to easily generate
passwords for a wanted scheme.

What scheme to use?
-------------------

With most installations it doesn't really matter what scheme you're using. If
you already have users with existing passwords, it's easiest to just keep using
the same scheme. Otherwise just pick something strong enough, for example SSHA.

The main idea behind storing passwords in non-plaintext scheme is that if an
attacker gets access to your server, he can't easily just get all users'
passwords and start using them. With stronger schemes it takes more time to
crack the passwords.

Non-plaintext authentication mechanisms
---------------------------------------

See <Authentication.Mechanisms.txt> for explanation of auth mechanisms. Most
installations use only plaintext mechanisms, so you can skip this section
unless you know you want to use them.

The problem with non-plaintext auth mechanisms is that the password must be
stored either in plaintext, or using a mechanism-specific scheme that's
incompatible with all other non-plaintext mechanisms. For example if you're
going to use CRAM-MD5 authentication, the password needs to be stored in either
PLAIN or CRAM-MD5 scheme. If you want to allow both CRAM-MD5 and DIGEST-MD5,
the password must be stored in plaintext.

In future it's possible that Dovecot could support multiple passwords in
different schemes for a single user.

Supported schemes
-----------------

*PLAIN*, *CRYPT* and *MD5-CRYPT* schemes were explained above.

Non-plaintext mechanism specific schemes:

 * *LANMAN*: DES-based encryption. Used sometimes with NTLM mechanism.
 * *NTLM*: MD4 sum of the password stored in hex. Used with NTLM mechanism.
 * *RPA*: Used with RPA mechanism.
 * *CRAM-MD5*: Used with CRAM-MD5 mechanism (v1.0.rc16 and later, for older use
   HMAC-MD5)
    * *HMAC-MD5*: Deprecated name for CRAM-MD5. The password isn't really in a
      standard HMAC-MD5 format.
 * *DIGEST-MD5*: Used with <DIGEST-MD5 mechanism>
   [Authentication.Mechanisms.DigestMD5.txt]. The username is included in the
   hash, so it's not possible to use the hash for different usernames.

MD5 based schemes:

 * *PLAIN-MD5*: MD5 sum of the password stored in hex.
 * *LDAP-MD5*: MD5 sum of the password stored in base64.
 * *SMD5*: Salted MD5 sum of the password stored in base64.

SHA based schemes:

 * *SHA*: SHA1 sum of the password stored in base64.
 * *SSHA*: Salted SHA1 sum of the password stored in base64.
 * *SHA256*: SHA256 sum of the password stored in base64. (v1.1 and later).
 * *SSHA256*: Salted SHA256 sum of the password stored in base64. (v1.2 and
   later).

For some schemes (e.g. PLAIN-MD5, SHA) Dovecot is able to detect if the
password hash is base64 or hex encoded, so both can be used.'dovecotpw' anyway
generates the passwords using the encoding mentioned above.

Encoding
--------

The base64 vs. hex encoding that is mentioned above is simply the default
encoding that is used. You can override it for any scheme by adding a ".hex",
".b64" or ".base64" suffix. For example:

 * '{SSHA.b64}986H5cS9JcDYQeJd6wKaITMho4M9CrXM' contains the password encoded
   to base64 (just like {SSHA})
 * '{SSHA.HEX}3f5ca6203f8cdaa44d9160575c1ee1d77abcf59ca5f852d1' contains the
   password encoded to hex

This can be especially useful with plaintext passwords to encode characters
that would otherwise be illegal. For example in passwd-file you couldn't use a
":" character in the password without encoding it to base64 or hex. For
example:'{PLAIN}{\}:!"' is the same as '{PLAIN.b64}e1x9OiEiCg=='.

You can also specify the encoding with dovecotpw. For example: 'dovecotpw -s
plain.b64' 

(This file was created from the wiki on 2009-01-05 04:42)
