Completed authentication function & login & logout.