Skip to content

Commit e17f521

Browse files
authored
Merge pull request #22 from Nullcaller/master
Add options for Courier authlib authentication
2 parents 6a9349c + f194c35 commit e17f521

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

lib/user_sql.php

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,22 @@ public function setPassword($uid, $password)
353353
elseif($this -> settings['set_crypt_type'] === 'password_hash')
354354
{
355355
$enc_password = $this->pw_hash($password);
356+
}
357+
elseif($this -> settings['set_crypt_type'] === 'courier_md5')
358+
{
359+
$enc_password = '{MD5}'.OC_USER_SQL::hex_to_base64(md5($password));
360+
}
361+
elseif($this -> settings['set_crypt_type'] === 'courier_md5raw')
362+
{
363+
$enc_password = '{MD5RAW}'.md5($password);
364+
}
365+
elseif($this -> settings['set_crypt_type'] === 'courier_sha1')
366+
{
367+
$enc_password = '{SHA}'.OC_USER_SQL::hex_to_base64(sha1($password));
368+
}
369+
elseif($this -> settings['set_crypt_type'] === 'courier_sha256')
370+
{
371+
$enc_password = '{SHA256}'.OC_USER_SQL::hex_to_base64(hash('sha256', $password, false));
356372
}
357373
else
358374
{
@@ -422,10 +438,26 @@ public function checkPassword($uid, $password)
422438
return false;
423439
$ret = sha1($salt['salt'].sha1($password)) === $db_pass;
424440
}
425-
441+
426442
elseif($this -> settings['set_crypt_type'] == 'sha1')
427443
{
428444
$ret = $this->hash_equals(sha1($password) , $db_pass);
445+
}
446+
elseif($this -> settings['set_crypt_type'] === 'courier_md5')
447+
{
448+
$ret = '{MD5}'.OC_USER_SQL::hex_to_base64(md5($password)) === $db_pass;
449+
}
450+
elseif($this -> settings['set_crypt_type'] === 'courier_md5raw')
451+
{
452+
$ret = '{MD5RAW}'.md5($password) === $db_pass;
453+
}
454+
elseif($this -> settings['set_crypt_type'] === 'courier_sha1')
455+
{
456+
$ret = '{SHA}'.OC_USER_SQL::hex_to_base64(sha1($password)) === $db_pass;
457+
}
458+
elseif($this -> settings['set_crypt_type'] === 'courier_sha256')
459+
{
460+
$ret = '{SHA256}'.OC_USER_SQL::hex_to_base64(hash('sha256', $password, false)) === $db_pass;
429461
} else
430462

431463
{
@@ -974,7 +1006,16 @@ function hash_equals( $a, $b ) {
9741006
}
9751007

9761008
return $result === 0;
977-
}
1009+
}
9781010

979-
}
1011+
private static function hex_to_base64($hex)
1012+
{
1013+
$hex_chr = '';
1014+
foreach(str_split($hex, 2) as $hexpair)
1015+
{
1016+
$hex_chr .= chr(hexdec($hexpair));
1017+
}
1018+
return base64_encode($hex_chr);
1019+
}
9801020

1021+
}

templates/admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<p><label for="col_displayname"><?php p($l -> t('Real Name Column')); ?></label><input type="text" id="col_displayname" name="col_displayname" value="<?php p($_['col_displayname']); ?>" /></p>
7171

7272
<p><label for="set_crypt_type"><?php p($l -> t('Encryption Type')); ?></label>
73-
<?php $crypt_types = array('md5' => 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'password_hash' => 'password_hash','mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption', 'joomla2' => 'Joomla > 2.5.18 phpass', 'ssha256' => 'Salted SSHA256', 'redmine' => 'Redmine', 'sha1' => 'SHA1'); ?>
73+
<?php $crypt_types = array('md5' => 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'password_hash' => 'password_hash','mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption', 'joomla2' => 'Joomla > 2.5.18 phpass', 'ssha256' => 'Salted SSHA256', 'redmine' => 'Redmine', 'sha1' => 'SHA1', 'courier_md5' => 'Courier base64-encoded MD5', 'courier_md5raw' => 'Courier hexadecimal MD5', 'courier_sha1' => 'Courier base64-encoded SHA1', 'courier_sha256' => 'Courier base64-encoded SHA256'); ?>
7474
<select id="set_crypt_type" name="set_crypt_type">
7575
<?php
7676
foreach ($crypt_types as $driver => $name):

0 commit comments

Comments
 (0)