refactors login, database works properly