some refactoring, implements HARTL-style encrypted login