// try to log a person in using a username and password public Person Login(string t_userName, string t_password) { Person retPerson_ = pd_.BloomFilterSearch(t_userName); // the person object to be returned if (retPerson_ == null) { return(null); // if person is not found, return null; } return(retPerson_.Password.TestPassword(t_password) ? retPerson_ // if retPerson_'s password is the same as t_password return retPerson_ : null); // otherwise return null /* old * return (retPerson_ = pd_.BloomFilterSearch(t_userName)) != null * && retPerson_.password.TestPassword(t_password) * ? retPerson_ * : null; // return null if */ }
// Handle auth setup private void HandleAuth() { const int MIN_USER_NAME_LEN = 1; const int MAX_USER_NAME_LEN = 100; if (lastUserName_ == txtInfo1_.Text && lastUserName_ != null) { // use cached username if (HandlePasswords()) { return; } goto success; // will i lose marks for using unconditional jumps? } // re-cache username lastUserName_ = null; if (string.IsNullOrWhiteSpace(txtInfo1_.Text) || // null check txtInfo1_.Text.Length < MIN_USER_NAME_LEN || // length check txtInfo1_.Text.Length > MAX_USER_NAME_LEN) { // invalid username Error(Errors.shortUsername); // show error message return; // fail } if (pd_.BloomFilterSearch(txtInfo1_.Text) != null) // test if person is already in database { // username has been taken Error(Errors.badUsername); // show error message return; // fail } // username has not been taken lastUserName_ = txtInfo1_.Text; // set cache to user input if (HandlePasswords()) // bad passwords { return; // fail } success :; nextUserName_ = txtInfo1_.Text; // set username to user input nextPassword_ = txtInfo2_.Text; // set password to user input ShowConfigSetup(); // show the config setup return; // success }