Implements routines of  login and logout