Implementation of the login function