added more digest-support to crypt-function

pull/21/head
defa 12 years ago
parent 5f8097b9eb
commit 5e9b40a0d5

@ -40,13 +40,33 @@ class rcube_sql_password
// crypted password // crypted password
if (strpos($sql, '%c') !== FALSE) { if (strpos($sql, '%c') !== FALSE) {
$salt = ''; $salt = '';
if (CRYPT_MD5) {
// Always use eight salt characters for MD5 (#1488136) if (!($crypt_digest = $rcmail->config->get('password_crypt_digest')))
$len = 8; $crypt_digest = CRYPT_MD5;
} else if (CRYPT_STD_DES) {
$len = 2; switch ($crypt_digest)
} else { {
return PASSWORD_CRYPT_ERROR; case CRYPT_MD5:
$len = 8;
$salt_digest = '$1$';
break;
case CRYPT_STD_DES:
$len = 2;
break;
case CRYPT_BLOWFISH:
$len = 22;
$salt_digest = '$2a$';
break;
case CRYPT_SHA256:
$len = 16;
$salt_digest = '$5$';
break;
case CRYPT_SHA512:
$len = 16;
$salt_digest = '$6$';
break;
default:
return PASSWORD_CRYPT_ERROR;
} }
//Restrict the character set used as salt (#1488136) //Restrict the character set used as salt (#1488136)
@ -55,7 +75,7 @@ class rcube_sql_password
$salt .= $seedchars[rand(0, 63)]; $salt .= $seedchars[rand(0, 63)];
} }
$sql = str_replace('%c', $db->quote(crypt($passwd, CRYPT_MD5 ? '$1$'.$salt.'$' : $salt)), $sql); $sql = str_replace('%c', $db->quote(crypt($passwd, $salt_digest ? $salt_digest .$salt.'$' : $salt)), $sql);
} }
// dovecotpw // dovecotpw

Loading…
Cancel
Save