update log and optimize the login function