public async Task AddNewAuthClient(AuthClient authClient, string password) { AuthClient existingUser; if (string.IsNullOrEmpty(authClient.UserName)) { existingUser = await _unitOfWork.AuthClients.GetAuthClientByApiKey(authClient.ApiKey); } else { existingUser = await _unitOfWork.AuthClients.GetAuthClientByName(authClient.UserName); } if (existingUser != null) { if (string.IsNullOrEmpty(authClient.UserName)) { throw new InvalidOperationException($"User {authClient.UserName} already exists"); } else { throw new InvalidOperationException($"User {authClient.UserName} already exists"); } } var hashedPassword = HashHelpers.HashPassword(password); authClient.RegisterDate = DateTime.UtcNow; authClient.PasswordHash = hashedPassword; authClient.Id = Guid.NewGuid(); _unitOfWork.AuthClients.AddAuthClient(authClient); _unitOfWork.Complete(); }
private void cmdSaveSettings_Click(object sender, EventArgs e) { using (var frm = Program.Container.Resolve <AuthForm>()) { var result = frm.ShowDialog(); if (result == DialogResult.Abort) { MessageBox.Show(Resources.PasswordInvalidMessage, Resources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (result != DialogResult.OK) { return; } } var settings = Settings.Default; settings.Cluster = txtCluster.Text; if (txtPassword.TextLength > 0) { settings.Password = HashHelpers.HashPassword(txtPassword.Text); } settings.Save(); MessageBox.Show(Resources.SettingsSavedMessage, Resources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information); }