improved login code and added a message on failure