Some documentation

Commented the majority of the "complex" functions in the login system to
explain some of the functionality.