private async void AddAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = LocalizationManager.GetStringByKey("String_Header_AddCredential")
            };

            CredentialViewModel credentialViewModel = new CredentialViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                CredentialInfo credentialInfo = new CredentialInfo
                {
                    ID       = instance.ID,
                    Name     = instance.Name,
                    Username = instance.Username,
                    Password = instance.Password
                };

                CredentialManager.AddCredential(credentialInfo);

                TimerLockUIStart(); // Reset timer
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, CredentialManager.GetNextID());

            customDialog.Content = new CredentialDialog
            {
                DataContext = credentialViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
        protected override void ProcessRecord()
        {
            if (Password == null || Password.Length == 0)
            {
                Host.UI.Write("Enter password: ");
                Password = Host.UI.ReadLineAsSecureString();
            }

#if !NETSTANDARD2_0
            CredentialManager.AddCredential(Name, Username, Password);
#else
            CredentialManager.AddCredential(Name, Username, Password, Overwrite.ToBool());
#endif
        }
        private async void EditAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = Application.Current.Resources["String_Header_EditCredential"] as string
            };

            CredentialViewModel credentialViewModel = new CredentialViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                CredentialManager.RemoveCredential(SelectedCredential);

                CredentialInfo credentialInfo = new CredentialInfo
                {
                    ID       = instance.ID,
                    Name     = instance.Name,
                    Username = instance.Username,
                    Password = instance.Password
                };

                CredentialManager.AddCredential(credentialInfo);

                TimerLockUIStart(); // Reset timer
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, SelectedCredential.ID, SelectedCredential);

            customDialog.Content = new CredentialDialog
            {
                DataContext = credentialViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
Ejemplo n.º 4
0
        public void CredentialTest()
        {
            var userName       = "******";
            var passWord       = "******";
            var securePassWord = "******";
            var appName        = "PnP.Core.Credential.Test.SecurePw";

            var result = CredentialManager.AddCredential(appName, userName, securePassWord.ToSecureString(), false);

            Assert.IsTrue(result);

            var result2 = CredentialManager.AddCredential(appName, userName, passWord, true);

            Assert.IsTrue(result2);

            var cred = CredentialManager.GetCredential(appName);

            if (!OperatingSystem.IsLinux())
            {
                Assert.IsTrue(cred != null);
                Assert.IsTrue(cred.UserName == userName);
                Assert.IsTrue(cred.Password == passWord);
            }
        }