Skip to content

Commit

Permalink
Resolve #695
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Nov 23, 2022
1 parent da98c61 commit 308be25
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions snappymail/v/0.0.0/app/libraries/snappymail/sasl/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ public function authenticate(string $username, string $passphrase, ?string $chal
{
// $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);
Expand Down
25 changes: 25 additions & 0 deletions test/sasl.php
Original file line number Diff line number Diff line change
@@ -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'));

0 comments on commit 308be25

Please sign in to comment.