This commit is contained in:
the-djmaze 2022-11-23 16:26:26 +01:00
parent da98c611e1
commit 308be25c24
2 changed files with 27 additions and 3 deletions

View file

@ -11,9 +11,8 @@ class Login extends \SnappyMail\SASL
{
// $challenge should be 'VXNlcm5hbWU6', but broken on some systems
// See https://github.com/the-djmaze/snappymail/issues/693
if ($challenge && \str_starts_with($this->decode($challenge), 'Username:')) {
// if ($challenge && 'Username:' !== $this->decode($challenge)) {
throw new \Exception("Invalid response: {$challenge}");
if ($challenge && !\str_starts_with($this->decode($challenge), 'Username:')) {
throw new \Exception("Invalid response: {$this->decode($challenge)}");
}
$this->passphrase = $passphrase;
return $this->encode($username);

25
test/sasl.php Normal file
View file

@ -0,0 +1,25 @@
<?php
//$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
//require '../index.php';
define('SNAPPYMAIL_LIBRARIES_PATH', dirname(__DIR__) . '/snappymail/v/0.0.0/app/libraries');
if (false === set_include_path(SNAPPYMAIL_LIBRARIES_PATH . PATH_SEPARATOR . get_include_path())) {
exit('set_include_path() failed. Probably due to Apache config using php_admin_value instead of php_value');
}
spl_autoload_extensions('.php');
/** lowercase autoloader */
spl_autoload_register();
/** case-sensitive autoloader */
spl_autoload_register(function($sClassName){
$file = SNAPPYMAIL_LIBRARIES_PATH . strtr($sClassName, '\\', DIRECTORY_SEPARATOR) . '.php';
// if ($file = stream_resolve_include_path(strtr($sClassName, '\\', DIRECTORY_SEPARATOR) . '.php')) {
if (is_file($file)) {
include_once $file;
}
});
$LOGIN = new \SnappyMail\SASL\Login;
$LOGIN->base64 = true;
var_dump($LOGIN->authenticate('john', 'doe', 'VXNlcm5hbWU6'));
var_dump($LOGIN->authenticate('john', 'doe', 'VXNlcm5hbWU6CG'));
var_dump($LOGIN->authenticate('john', 'doe', 'UGFzc3dvcmQ6'));