@@ -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+ }
0 commit comments