Пример #1
0
        internal static X509Certificate2 PfxPrompt(StoreLocation loc)
        {
            var fileDiag = new VistaOpenFileDialog()
            {
                ShowHelp         = true,
                Filter           = "PFX certificates (*.pfx)|*.pfx",
                InitialDirectory = Environment.GetEnvironmentVariable("USERPROFILE") + "\\Desktop",
                Multiselect      = false,
                Title            = "Select a password protected pfx file"
            };

            if (fileDiag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var pfxPass = new CredentialDialog
                {
                    ShowSaveCheckBox                      = false,
                    MainInstruction                       = "Enter the password for the protected pfx file.",
                    Content                               = "The USERNAME does not matter.",
                    Target                                = "MainWindow",
                    ShowUIForSavedCredentials             = false,
                    UseApplicationInstanceCredentialCache = false
                };
                if (pfxPass.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    X509Certificate2 cert = Encryption.InstallPfx(fileDiag.FileName, pfxPass.Credentials.SecurePassword, loc);
                    return(cert);
                }
            }
            return(null);
        }
Пример #2
0
        private void ShowCredentialDialogV2()
        {
            using (CredentialDialog dialog = new CredentialDialog())
            {
                // The window title will not be used on Vista and later; there the title will always be "Windows Security".
                dialog.WindowTitle     = "Credential dialog sample";
                dialog.MainInstruction = "Please enter your username and password.";
                dialog.Content         = "Since this is a sample the credentials won't be used for anything, so you can enter anything you like.";
                //dialog.ShowSaveCheckBox = false;
                dialog.ShowUIForSavedCredentials = true;

                dialog.UserName = "******";
                // The target is the key under which the credentials will be stored.
                // It is recommended to set the target to something following the "Company_Application_Server" pattern.
                // Targets are per user, not per application, so using such a pattern will ensure uniqueness.
                dialog.Target = "Ookii_DialogsWpfSample_www.example.com";
                if (dialog.ShowDialog(this, (int)CredUIWinFlags.InCredOnly, 0))
                {
                    MessageBox.Show(this, string.Format("You entered the following information:\nUser name: {0}\nPassword: {1}", dialog.Credentials.UserName, dialog.Credentials.Password), "Credential dialog sample");
                    // Normally, you should verify if the credentials are correct before calling ConfirmCredentials.
                    // ConfirmCredentials will save the credentials if and only if the user checked the save checkbox.
                    //if (dialog.ShowSaveCheckBox)
                    //    dialog.ConfirmCredentials(true);
                }
            }
        }
Пример #3
0
        private static ICredentials PromptUserForCredentials(Uri uri, bool forcePrompt)
        {
            string proxyHost         = uri.Host;
            string credentialsTarget = string.Format(CultureInfo.InvariantCulture, "PackageExplorer_{0}", proxyHost);

            ICredentials basicCredentials = null;

            using (var dialog = new CredentialDialog())
            {
                dialog.Target      = credentialsTarget;
                dialog.WindowTitle = string.Format(
                    CultureInfo.CurrentCulture, Resources.Resources.ProxyConnectToMessage, proxyHost);

                dialog.MainInstruction           = dialog.WindowTitle;
                dialog.ShowUIForSavedCredentials = forcePrompt;
                dialog.ShowSaveCheckBox          = true;
                if (dialog.ShowDialog())
                {
                    basicCredentials = dialog.Credentials;
                    if (dialog.IsSaveChecked)
                    {
                        CredentialDialog.StoreCredential(credentialsTarget, dialog.Credentials);
                    }
                }
            }
            return(basicCredentials);
        }
Пример #4
0
        public bool OpenCredentialsDialog(string target, out NetworkCredential networkCredential)
        {
            using (var dialog = new CredentialDialog())
            {
                dialog.WindowTitle     = Resources.Dialog_Title;
                dialog.MainInstruction = "Credentials for " + target;
                dialog.Content         = "Enter Personal Access Tokens in the username field.";
                dialog.Target          = target;

                try
                {
                    if (dialog.ShowDialog())
                    {
                        networkCredential = dialog.Credentials;
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    Show(e.Message, MessageLevel.Error);
                }

                networkCredential = null;
                return(false);
            }
        }
Пример #5
0
 /// <summary>
 /// Prompts user to provide new credentials for logon.  Returns true if credentials successfully validate to ActiveDirectory server.
 /// </summary>
 /// <returns>Returns true if credentials validate with ActiveDirectory.  If validation fails, returns false.</returns>
 public static bool ChangeLogon()
 {
     using (CredentialDialog dialog = new CredentialDialog()
     {
         Target = "us.paschalcorp.com",
         MainInstruction = "Please supply logon credentials."
     }) {
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             if (context.ValidateCredentials(dialog.UserName, dialog.Password))
             {
                 cred         = new NetworkCredential(dialog.UserName, dialog.Password);
                 searcher     = new DirectorySearcher(new DirectoryEntry(searcher.SearchRoot.Path, cred.UserName, cred.Password));
                 termSearcher = new DirectorySearcher(new DirectoryEntry(termSearcher.SearchRoot.Path, cred.UserName, cred.Password));
                 context      = new PrincipalContext(ContextType.Domain, "us.paschalcorp.com", cred.UserName, cred.Password);
                 return(true);
             }
             else
             {
                 MessageBox.Show("Credentials failed to validate.  Current logon has not changed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     return(false);
 }
Пример #6
0
        public bool OpenCredentialsDialog(string target, out NetworkCredential?networkCredential)
        {
            DiagnosticsClient.TrackEvent("UIServices_OpenCredentialsDialog");
            using var dialog = new CredentialDialog
                  {
                      WindowTitle     = Resources.Dialog_Title,
                      MainInstruction = "Credentials for " + target,
                      Content         = "Enter Personal Access Tokens in the username field.",
                      Target          = target
                  };

            try
            {
                if (dialog.ShowDialog())
                {
                    networkCredential = dialog.Credentials;
                    return(true);
                }
            }
            catch (Exception e)
            {
                Show(e.Message, MessageLevel.Error);
            }

            networkCredential = null;
            return(false);
        }
Пример #7
0
        private bool ldisplay()
        {
            string strUsername = "";
            string strPassword = "";

            CredentialDialog crDiag = new CredentialDialog();

            crDiag.Content         = "";
            crDiag.MainInstruction = "Please enter your username and password";
            crDiag.Target          = "SampleUI";

            crDiag.ShowDialog();

            strUsername = crDiag.UserName;
            strPassword = crDiag.Password;
            Debug.Write(strUsername + strPassword);

            if (strUsername.Equals("admin") && strPassword.Equals("admin"))
            {
                return(true);
            }
            else
            {
                System.Windows.MessageBox.Show("Invalid Login", "Oops");
                return(false);
            }
        }
Пример #8
0
        // ReSharper disable once UnusedMember.Global
        public static Configuration GetConfiguration(string url, string orgName = null, bool useDefaultCredentials = false)
        {
            ClientCredentials clientCredentials;

            if (useDefaultCredentials)
            {
                clientCredentials = new ClientCredentials();
                clientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            }
            else
            {
                var dialog =
                    new CredentialDialog
                {
                    MainInstruction  = "Please enter your CRM credentials",
                    ShowSaveCheckBox = true,
                    UseApplicationInstanceCredentialCache = true,
                    ShowUIForSavedCredentials             = true,
                    Target      = "OwnSpace_CRMSDK_",
                    WindowTitle = "Credentials dialog"
                };
                var dialogResult = dialog.ShowDialog();
                if (dialogResult == DialogResult.OK)
                {
                    dialog.ConfirmCredentials(true);

                    var authCredentials = new AuthenticationCredentials();
                    authCredentials.ClientCredentials.UserName.UserName = dialog.Credentials.UserName;
                    authCredentials.ClientCredentials.UserName.Password = dialog.Credentials.Password;
                    clientCredentials = authCredentials.ClientCredentials;
                }
                else
                {
                    return(null);
                }
            }

            var organizationServiceUri        = GetOrganizationServiceUri(url, orgName);
            var discoveryServiceUri           = GetDiscoveryServiceUri(url, orgName);
            var organizationServiceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>(organizationServiceUri);
            var discoveryServiceManagement    = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>(discoveryServiceUri);
            var config =
                new Configuration(url, orgName, organizationServiceManagement.AuthenticationType)
            {
                OrganizationUri = organizationServiceUri,
                DiscoveryUri    = discoveryServiceUri,
                Credentials     = clientCredentials,
                OrganizationServiceManagement = organizationServiceManagement,
                DiscoveryServiceManagement    = discoveryServiceManagement
            };

            config.Credentials = FulfillCredentials(config);

            return(config);
        }
Пример #9
0
        async Task <XDocument> Get(Uri uri)
        {
            HttpStatusCode statusCode;

            using (var result = await client.GetAsync(uri))
            {
                if (result.IsSuccessStatusCode)
                {
                    using (var stream = await result.Content.ReadAsStreamAsync())
                    {
                        return(await Task.Run(() => XDocument.Load(stream)));
                    }
                }
                statusCode = result.StatusCode;
                IEnumerable <string> authHeader;
                if (statusCode == HttpStatusCode.Found &&
                    result.Headers.TryGetValues("X-com-ibm-team-repository-web-auth-msg", out authHeader) &&
                    authHeader.SequenceEqual(new[] { "authrequired" }))
                {
                    statusCode = HttpStatusCode.Unauthorized;
                }
            }
            if (statusCode == HttpStatusCode.Unauthorized)
            {
                var dialog = new CredentialDialog
                {
                    MainInstruction = "Enter your Jazz credentials",
                    Content         = "This is probably the same as your corp credentials.",
                    WindowTitle     = this.Title,
                    Target          = "jazz:clm1.waters.com"
                };
                if (dialog.ShowDialog(this) != true)
                {
                    throw new ApplicationException("User did not enter credentials");
                }
                var authUri = new Uri("https://clm1.waters.com/jts/authenticated/j_security_check");
                //var request = new HttpRequestMessage(HttpMethod.Get, authUri);
                var authBody = new FormUrlEncodedContent(new Dictionary <string, string>
                {
                    { "j_username", dialog.UserName },
                    { "j_password", dialog.Password }
                });
                using (var authResult = await client.PostAsync(authUri, authBody))
                {
                    if (authResult.IsSuccessStatusCode && authResult.StatusCode != HttpStatusCode.Found ||
                        authResult.Headers.Location.AbsolutePath != "/jts/authenticated/")
                    {
                        throw new ApplicationException("Authentication failed");
                    }
                }
                return(await Get(uri));
            }
            throw new ApplicationException($"Got error {statusCode}");
        }
Пример #10
0
        private void ShowCredentialDialog()
        {
            try
            {
                var isLogin = FindElement.Settings.CredentialLogin;
                if (isLogin)
                {
                    using (CredentialDialog dialog = new CredentialDialog())
                    {
                        dialog.WindowTitle     = "ورود به نرم افزار";
                        dialog.MainInstruction = "لطفا نام کاربری و رمز عبور خود را وارد کنید";
                        //dialog.Content = "";
                        dialog.ShowSaveCheckBox          = true;
                        dialog.ShowUIForSavedCredentials = true;
                        // The target is the key under which the credentials will be stored.
                        dialog.Target = "Mahdi72_MoalemYar_www.127.0.0.1.com";

                        try
                        {
                            while (isLogin)
                            {
                                if (dialog.ShowDialog(this))
                                {
                                    using (var db = new DataClass.myDbContext())
                                    {
                                        var usr = db.Users.Where(x => x.Username == dialog.Credentials.UserName && x.Password == dialog.Credentials.Password);
                                        if (usr.Any())
                                        {
                                            dialog.ConfirmCredentials(true);
                                            isLogin = false;
                                        }
                                        else
                                        {
                                            dialog.Content = "مشخصات اشتباه است دوباره امتحان کنید";
                                        }
                                    }
                                }
                                else
                                {
                                    Environment.Exit(0);
                                }
                            }
                        }
                        catch (InvalidOperationException)
                        {
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Пример #11
0
        internal CredentialDialog CreateCredentialDialog()
        {
            var dialog = new CredentialDialog
            {
                MainInstruction  = MAIN_INSTRUCTION,
                Content          = CONTENT,
                ShowSaveCheckBox = false,
                Target           = TARGET,
                WindowTitle      = CRED_WINDOW_TITLE
            };

            return(dialog);
        }
Пример #12
0
        private void button5_Click(object sender, EventArgs e)
        {
            //try
            //{


            CredentialDialog crDiag = new CredentialDialog();

            crDiag.Content         = "Suas informações são necessárias para conectar ao banco SQL.";
            crDiag.MainInstruction = "Por favor, entre com o formato: servidor:banco@usuario e senha";
            crDiag.Target          = "Leitor de Catálogo Bizagi";
            crDiag.UseApplicationInstanceCredentialCache = true;

            if (crDiag.ShowDialog() == DialogResult.OK)
            {
                var udata = crDiag.UserName.Split('@');
                var sData = udata[0].Split(':');
                this.strUsername = udata[1].Trim();
                this.strPassword = crDiag.Password;
                this.strServer   = sData[0].Trim();
                this.strDataBase = sData[1].Trim();
                Dictionary <string, string> filesxml = new Dictionary <string, string>();
                filesxml.Add("BizagiInfo.xml", "");
                filesxml.Add("Catalog__Indexes.xml", "");
                filesxml.Add("Catalog__IndexObjects.xml", "");
                filesxml.Add("Catalog__Localization.xml", "");
                filesxml.Add("Catalog__Objects.xml", "");
                filesxml.Add("Catalog__References.xml", "");
                filesxml.Add("Options.xml", "");
                filesxml.Add("PackageInfo.xml", "");
                filesxml.Add("Relational.xml", "");

                loadSQLs(filesxml);
                propertyGrid1.SelectedObject = filesxml;
                comboBox1.Items.Clear();
                foreach (var i in filesxml)
                {
                    comboBox1.Items.Add(new ComboIten {
                        Name = i.Key, Value = i.Value, isSQL = true
                    });
                }
            }
            //}
            //catch (Exception ex)
            //{

            //    MessageBox.Show(ex.Message);
            //}
        }
Пример #13
0
        private void CredButton_Click(object sender, RoutedEventArgs e)
        {
            var click = new RoutedEventArgs(Button.ClickEvent);

            if ((string)this.CredsButton.Content == RUN_AS)
            {
                using (CredentialDialog dialog = this.CreateCredentialDialog())
                {
                    bool res = false;
                    do
                    {
                        bool done = dialog.ShowDialog(this);
                        if (done)
                        {
                            Creds = (ADCredential)dialog.Credentials;
                            if (!Creds.TryAuthenticate(out Exception caught))
                            {
                                res = ShowErrorMessage(caught, true);
                                if (res)
                                {
                                    continue;
                                }

                                else
                                {
                                    break;
                                }
                            }
                            else
                            {
                                res = false;
                            }

                            break;
                        }
                    }while (res);

                    this.HandleReprompt(click);
                }
            }
            else
            {
                this.Dispatcher.Invoke(() =>
                {
                    this.RelaunchBtn.RaiseEvent(click);
                });
            }
        }
        public override IDisposable Login(LoginConfig config)
        {
            var dlg = new CredentialDialog {
                //UserName = config.LoginValue ?? String.Empty,
                WindowTitle      = config.Title,
                Content          = config.Message,
                ShowSaveCheckBox = false
            };

            //dlg.MainInstruction
            dlg.ShowDialog();

            config.OnAction(new LoginResult(
                                true,
                                dlg.UserName,
                                dlg.Password
                                ));
            return(new DisposableAction(dlg.Dispose));
        }
Пример #15
0
        public bool OpenCredentialsDialog(string target, out NetworkCredential networkCredential)
        {
            using (var dialog = new CredentialDialog())
            {
                dialog.WindowTitle     = Resources.Resources.Dialog_Title;
                dialog.MainInstruction = "Credentials for " + target;
                dialog.Content         = "Enter PATs in the username field.";
                dialog.Target          = target;

                if (dialog.ShowDialog())
                {
                    networkCredential = dialog.Credentials;
                    return(true);
                }

                networkCredential = null;
                return(false);
            }
        }
Пример #16
0
        private void ConnectAction()
        {
            if (IsConnected || _dialer.IsBusy)
            {
                return;
            }

            _dialer.DialCompleted += DialCompleted;
            _dialer.StateChanged  += StateChanged;
            _dialer.Error         += DialError;

#if !DEBUG
            _credentials = CredentialDialog.RetrieveCredential(Unique);
#endif
            if (_credentials == null)
            {
                _dialog                  = new CredentialDialog();
                _dialog.WindowTitle      = "Vemeo VPN Authentication"; // XP Only
                _dialog.MainInstruction  = "Please enter your vemeo.com username and password.";
                _dialog.ShowSaveCheckBox = true;
                _dialog.IsSaveChecked    = true;
#if DEBUG
                _dialog.ShowUIForSavedCredentials = true;
#else
                _dialog.ShowUIForSavedCredentials = false;
#endif
                _dialog.Target = Unique;
                if (_dialog.ShowDialog())
                {
                    _credentials = _dialog.Credentials;
                }
            }

            if (_credentials != null)
            {
                Connect();
            }
        }
Пример #17
0
        private void DialCompleted(object sender, DialCompletedEventArgs e)
        {
            if (_dialog != null && !_dialog.IsStoredCredential)
            {
                _dialog.ConfirmCredentials(e.Connected);
            }
            else if (!e.Connected)
            {
                CredentialDialog.DeleteCredential(Unique);
            }

            IsConnected = e.Connected;

            if (IsConnected)
            {
                var ifn = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(i => i.Name == VpnName);
                if (ifn != null)
                {
                    var ifprop = ifn.GetIPProperties();
                    var ifip   = ifprop.UnicastAddresses.FirstOrDefault(ip => ip.Address.AddressFamily == AddressFamily.InterNetwork && !IPAddress.IsLoopback(ip.Address));
                    var prop   = ifprop.GetIPv4Properties();

                    var ifindex = ifprop.GetIPv4Properties().Index;

                    // add routes
                    var ips = Hosts.SelectMany(hst => hst.IPAddresses);

                    foreach (var ipAddress in ips)
                    {
                        string message = string.Empty;

                        NativeMethods.ModifyIpForwardEntry(true, ipAddress.ToString(), "255.255.255.255", ifip.Address.ToString(), (uint)ifindex, /* todo: proper metric */ (uint)ifindex, out message);
                        Debug.WriteLine(message);
                    }
                }
            }
        }
Пример #18
0
        public bool OpenCredentialsDialog(string target, out NetworkCredential?networkCredential)
        {
            DiagnosticsClient.TrackEvent("UIServices_OpenCredentialsDialog");
            using var dialog = new CredentialDialog
                  {
                      WindowTitle               = Resources.Dialog_Title,
                      MainInstruction           = "Credentials for " + target,
                      Content                   = "Enter Personal Access Tokens in the username field.",
                      Target                    = target,
                      ShowSaveCheckBox          = true, // Allow user to save the credentials to operating system's credential manager
                      ShowUIForSavedCredentials = false // Do not show dialog when credentials can be grabbed from OS credential manager
                  };

            try
            {
                // Show dialog or query credential manager
                if (dialog.ShowDialog())
                {
                    // When dialog was shown
                    if (!dialog.IsStoredCredential)
                    {
                        // Save the credentials when save checkbox was checked
                        dialog.ConfirmCredentials(true);
                    }
                    networkCredential = dialog.Credentials;
                    return(true);
                }
            }
            catch (Exception e)
            {
                Show(e.Message, MessageLevel.Error);
            }

            networkCredential = null;
            return(false);
        }
Пример #19
0
        public override IDisposable Login(LoginConfig config)
        {
            var dlg = new CredentialDialog
            {
                //UserName = config.LoginValue ?? String.Empty,
                WindowTitle = config.Title,
                Content = config.Message,
                ShowSaveCheckBox = false
            };
            //dlg.MainInstruction
            dlg.ShowDialog();

            config.OnAction(new LoginResult(
                true,
                dlg.UserName,
                dlg.Password
            ));
            return new DisposableAction(dlg.Dispose);
        }
Пример #20
0
 private void ShowCredentialDialog()
 {
     using( CredentialDialog dialog = new CredentialDialog() )
     {
         // The window title will not be used on Vista and later; there the title will always be "Windows Security".
         dialog.WindowTitle = "Credential dialog sample";
         dialog.MainInstruction = "Please enter your username and password.";
         dialog.Content = "Since this is a sample the credentials won't be used for anything, so you can enter anything you like.";
         dialog.ShowSaveCheckBox = true;
         dialog.ShowUIForSavedCredentials = true;
         // The target is the key under which the credentials will be stored.
         // It is recommended to set the target to something following the "Company_Application_Server" pattern.
         // Targets are per user, not per application, so using such a pattern will ensure uniqueness.
         dialog.Target = "Ookii_DialogsWpfSample_www.example.com";
         if( dialog.ShowDialog(this) )
         {
             MessageBox.Show(this, string.Format("You entered the following information:\nUser name: {0}\nPassword: {1}", dialog.Credentials.UserName, dialog.Credentials.Password), "Credential dialog sample");
             // Normally, you should verify if the credentials are correct before calling ConfirmCredentials.
             // ConfirmCredentials will save the credentials if and only if the user checked the save checkbox.
             dialog.ConfirmCredentials(true);
         }
     }
 }