initial registration and login code (needs refactoring)