internal static CRegistationResult RegisterPerson(String name, String username, String email, SecureString securePassword, SecureString securePasswordConfirmation) { CRegistationResult result = new CRegistationResult(); String password = securePassword.ConvertToUnsecureString(); String passwordConfirmation = securePasswordConfirmation.ConvertToUnsecureString(); result.IsEmailValidated = IsMailValid(email); result.IsPasswordValidated = IsPasswordValid(password); result.IsPasswordConfirmed = password.Equals(passwordConfirmation); if (!result.IsEmailValidated || !result.IsPasswordValidated || !result.IsPasswordConfirmed) { result.IsRegistered = false; return(result); } CDataSupplierProxy dataSupplier = new CDataSupplierProxy(); result.IsUsernameFree = !dataSupplier.IsUsernameExisted(username); result.IsEmailFree = !dataSupplier.IsEmailExisted(email); if (!result.IsUsernameFree || !result.IsEmailFree) { result.IsRegistered = false; return(result); } CDataRecorderProxy dataRecorder = new CDataRecorderProxy(); String salt = GenerateRandomString(10); String passwordHash = CalculateHash(SaltPassword(password, salt)); try { dataRecorder.RegisterPerson(name, username, email, salt, passwordHash); } //TODO: Find what exception throw when added new entity with existed primary Key or unique field dublicate catch (Exception ex) { log.Error(ex, "Some error occure while trying to register person in CSLoginServis. Message: {0}", ex.Message); result.IsRegistered = false; return(result); } CLoginVerificationResult verRes = VerifyPassword(username, securePassword); if (verRes.IsVerified) { result.Token = verRes.Token; result.IsRegistered = true; } else { result.IsRegistered = false; } return(result); }
public CLoginVerificationResult VerifyPassword(String username, String plainPassword) { try { log.Trace("Entered VerifyPassword"); ILoginBllFacade loginProxy = new CLoginBllFacadeProxy(); LoginService.CLoginVerificationResult loginServiceResponce = loginProxy.VerifyPassword(username, plainPassword); return(CSLoginToBllConverter.ConverLoginVerification(loginServiceResponce)); } catch (Exception ex) { log.Error(ex, "Some error occure in CBllFacadeForUI.VerifyPassword. Message: {0}", ex.Message); return(null); } }