Sometimes i’ve been in the need to test my mail server auth feature (smtp).
Doing it using plain password is a little insecure. So you need to use some encoding. Most usual is base 64.
The way for computing the auth string to send the mailserver, is joining both values (user and password) using a “0″ char as glue (not the number 0, the character 0).
Even easier (and lazier), using this script :
<? # Use the script as php auth.php user password $user = $argv; $pass = $argv; $unenc = implode("\000",array($user,$pass)); echo "AUTH LOGIN " . base64_encode("$unenc") . "\n"; echo "AUTH PLAIN " . base64_encode("\000$unenc") . "\n"; ?>
Using this script, and trying an user/pass combo, would give :
# php auth.php email@example.com password1 AUTH LOGIN dXNlcjFAZG9tYWluLmNvbQBwYXNzd29yZDE= AUTH PLAIN AHVzZXIxQGRvbWFpbi5jb20AcGFzc3dvcmQx
This, of course, is using command line.