Add options for Courier authlib authentication to user_sql.php

Availible options:
courier_md5 – base64-encoded md5
courier_md5raw – hexadecimal md5
courier_sha1 – base64-encoded sha1
courier_sha256 – base64-encoded sha256
This commit is contained in:
Nullcaller
2018-02-10 04:21:12 +03:00
parent 6a9349c02a
commit b456f6c921

View File

@@ -353,6 +353,22 @@ class OC_USER_SQL extends BackendUtility implements \OCP\IUserBackend,
elseif($this -> settings['set_crypt_type'] === 'password_hash')
{
$enc_password = $this->pw_hash($password);
}
elseif($this -> settings['set_crypt_type'] === 'courier_md5')
{
$enc_password = '{MD5}'.OC_USER_SQL::hex_to_base64(md5($password));
}
elseif($this -> settings['set_crypt_type'] === 'courier_md5raw')
{
$enc_password = '{MD5RAW}'.md5($password);
}
elseif($this -> settings['set_crypt_type'] === 'courier_sha1')
{
$enc_password = '{SHA}'.OC_USER_SQL::hex_to_base64(sha1($password));
}
elseif($this -> settings['set_crypt_type'] === 'courier_sha256')
{
$enc_password = '{SHA256}'.OC_USER_SQL::hex_to_base64(hash('sha256', $password, false));
}
else
{
@@ -426,6 +442,22 @@ class OC_USER_SQL extends BackendUtility implements \OCP\IUserBackend,
elseif($this -> settings['set_crypt_type'] == 'sha1')
{
$ret = $this->hash_equals(sha1($password) , $db_pass);
}
elseif($this -> settings['set_crypt_type'] === 'courier_md5')
{
$ret = '{MD5}'.OC_USER_SQL::hex_to_base64(md5($password)) === $db_pass;
}
elseif($this -> settings['set_crypt_type'] === 'courier_md5raw')
{
$ret = '{MD5RAW}'.md5($password) === $db_pass;
}
elseif($this -> settings['set_crypt_type'] === 'courier_sha1')
{
$ret = '{SHA}'.OC_USER_SQL::hex_to_base64(sha1($password)) === $db_pass;
}
elseif($this -> settings['set_crypt_type'] === 'courier_sha256')
{
$ret = '{SHA256}'.OC_USER_SQL::hex_to_base64(hash('sha256', $password, false)) === $db_pass;
} else
{
@@ -976,5 +1008,14 @@ class OC_USER_SQL extends BackendUtility implements \OCP\IUserBackend,
return $result === 0;
}
private static function hex_to_base64($hex)
{
$hex_chr = '';
foreach(str_split($hex, 2) as $hexpair)
{
$hex_chr .= chr(hexdec($hexpair));
}
return base64_encode($hex_chr);
}
}