Extract login-related functions to login.js