Fix for 'smart auth' pull request #1398

This pull request replaces #1398.  It includes all the fixes for all the issues I've spotted.  I also cleaned up the format, and added more documentation.  Tested on these authentication methods: Basic, Digest, Negotiate, and NTLM on Apache and IIS.

Closes #1398