Complete auto login and logout function.