Completed implementation of login handling (still not functional)