DiscoveryClientProtocol DiscoverWebServices(string url) { WebServiceDiscoveryClientProtocol protocol = new WebServiceDiscoveryClientProtocol(); NetworkCredential credential = CredentialCache.DefaultNetworkCredentials; bool retry = true; while (retry) { try { protocol.Credentials = credential; protocol.DiscoverAny(url); protocol.ResolveOneLevel(); return(protocol); } catch (WebException ex) { if (protocol.IsAuthenticationRequired) { using (UserCredentialsDialog dialog = new UserCredentialsDialog(url, protocol.GetAuthenticationHeader().AuthenticationType)) { if (dialog.ShowDialog() == DialogResult.OK) { credential = dialog.Credential; } else { retry = false; } } } else { throw ex; } } } return(null); }
public void CustomizeDialogTest() { using (UserCredentialsDialog dialog = new UserCredentialsDialog("mytarget", "MyApplication", "Enter your creds")) { dialog.ShowDialog(); } }
public void GetUserNamePassword() { using (var dialog = new UserCredentialsDialog()) { if (dialog.ShowDialog() == DialogResult.OK) { if (!this._svn.DownLoadLatestProgressTrackingSheet(dialog.User, dialog.PasswordToString())) { MessageBox.Show("Invalid username or password. Try gain"); return; } Settings.Default.UserName = _userName = dialog.User; Settings.Default.Password = _password = dialog.PasswordToString(); Settings.Default.Save(); this._svn.IsValidUser(Settings.Default.UserName, Settings.Default.Password); if (dialog.SaveChecked) { dialog.ConfirmCredentials(true); } } } }
public void OnlyAdminAccountTest() { using (UserCredentialsDialog dialog = new UserCredentialsDialog("OnlyAdminApp")) { // Add to the Default flags the Admin only filter dialog.Flags |= UserCredentialsDialogFlags.RequestAdministrator; dialog.ShowDialog(); } }
public void ReadOnlyNotSaveCredsTest() { using (UserCredentialsDialog dialog = new UserCredentialsDialog()) { dialog.Flags = UserCredentialsDialogFlags.KeepUsername | UserCredentialsDialogFlags.DoNotPersist; // Preload the user to some value dialog.User = Environment.UserName; dialog.Domain = Environment.UserDomainName; dialog.ShowDialog(); } }
public void RunAsProcessTest() { using (UserCredentialsDialog dialog = new UserCredentialsDialog()) { if (dialog.ShowDialog() == DialogResult.OK) { ProcessStartInfo info = new ProcessStartInfo("notepad.exe"); info.UseShellExecute = false; info.UserName = dialog.User; info.Password = dialog.Password; info.Domain = dialog.Domain; using (Process install = Process.Start(info)) { install.WaitForExit(); Console.WriteLine(install.ExitCode); } } } }
public void DefaultFlagsTest() { using (UserCredentialsDialog dialog = new UserCredentialsDialog()) { if (dialog.ShowDialog() == DialogResult.OK) { // validate credentials against an authentication authority // ... // If credentials are valid // and the user checked the "remember my password" option if (dialog.SaveChecked) { dialog.ConfirmCredentials(true); } Console.WriteLine(dialog.User); Console.WriteLine(dialog.PasswordToString()); Console.WriteLine(dialog.Domain); } } }
private static void Main(string[] args) { WebRequest.DefaultWebProxy = null; if (args.Length == 0) { MessageBox.Show("Parameter required: ScreenConnect URL", "ScreenConnect Tray", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } String bUrl = args[0]; UserCredentialsDialog ucd = new UserCredentialsDialog(bUrl, "Login to ScreenConnect", "Enter ScreenConnect password"); String oneTimePassword = null; sc = new SCHostInterface(bUrl); while (true) { if (oneTimePassword == null && ucd.ShowDialog() == DialogResult.Cancel) { return; } try { if (oneTimePassword == null) { sc.Login(ucd.User, ucd.PasswordToString()); } else { try { sc.LoginOneTimePassword(oneTimePassword); } finally { oneTimePassword = null; } } ucd.ConfirmCredentials(true); break; } catch (ScreenConnectAuthenticationException e) { if (e.OneTimePasswordRequired) { DialogResult dResult = InputBox("One Time Password", "Enter One Time Password:", ref oneTimePassword); if (dResult == DialogResult.OK) { continue; } } ucd.Flags = UserCredentialsDialogFlags.IncorrectPassword; ucd.ConfirmCredentials(false); continue; } catch (WebException e) { if (e.Status == WebExceptionStatus.ProtocolError) { ucd.Flags = UserCredentialsDialogFlags.IncorrectPassword; ucd.ConfirmCredentials(false); continue; } MessageBox.Show(e.ToString(), e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (Exception e) { MessageBox.Show(e.ToString(), e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } Application.Run(new Program()); }