fixed login implementation. TODO: test it