Functionality for login()