Remove() public method

public Remove ( [ credential ) : void
credential [
return void
 public void Remove(string resource, string userName)
 {
     try
     {
         var credential = _passwordVault.Retrieve(resource, userName);
         _passwordVault.Remove(credential);
     }
     catch (Exception)
     {
         //No matching resource
     }
 }
        // Define a method that performs the authentication process
        // using a Facebook sign-in. 
        //private async System.Threading.Tasks.Task AuthenticateAsync()
        //{
        //    while (user == null)
        //    {
        //        string message;
        //        try
        //        {
        //            // Change 'MobileService' to the name of your MobileServiceClient instance.
        //            // Sign-in using Facebook authentication.
        //            user = await App.MobileService
        //                .LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);
        //            message =
        //                string.Format("You are now signed in - {0}", user.UserId);
        //        }
        //        catch (InvalidOperationException)
        //        {
        //            message = "You must log in. Login Required";
        //        }

        //        var dialog = new MessageDialog(message);
        //        dialog.Commands.Add(new UICommand("OK"));
        //        await dialog.ShowAsync();
        //    }
        //}

        public override async void LogoutAsync()
        {
            App.MobileService.Logout();

            string message;
            // This sample uses the Facebook provider.
            var provider = "AAD";

            // Use the PasswordVault to securely store and access credentials.
            PasswordVault vault = new PasswordVault();
            PasswordCredential credential = null;
            try
            {
                // Try to get an existing credential from the vault.
                credential = vault.FindAllByResource(provider).FirstOrDefault();
                vault.Remove(credential);
            }
            catch (Exception)
            {
                // When there is no matching resource an error occurs, which we ignore.
            }
            message = string.Format("You are now logged out!");
            var dialog = new MessageDialog(message);
            dialog.Commands.Add(new UICommand("OK"));
            await dialog.ShowAsync();
            IsLoggedIn = false;

        }
Beispiel #3
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            TextBox InputResourceValue = rootPage.FindName("InputResourceValue") as TextBox;
            TextBox InputUserNameValue = rootPage.FindName("InputUserNameValue") as TextBox;
            String  result             = "";

            if (InputResourceValue.Text == "" || InputUserNameValue.Text == "")
            {
                DebugPrint("Inputs are missing. Resource and Username are required.");
            }
            else
            {
                try
                {
                    //
                    //this is the code to remove a credentialt from PasswordVault by supplying resource or username
                    //
                    Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                    PasswordCredential cred = vault.Retrieve(InputResourceValue.Text, InputUserNameValue.Text);
                    vault.Remove(cred);
                    result = "Credential removed successfully. Resource: " + InputResourceValue.Text + " Username: "******".";
                    DebugPrint(result.ToString());
                }
                catch (Exception Error) // No stored credentials, so none to delete
                {
                    DebugPrint(Error.Message);
                }
            }
        }
Beispiel #4
0
        private static void Save()
        {
            if (credential != null)
            {
                vault.Remove(credential);
            }

            credential = new PasswordCredential();

            if (!string.IsNullOrEmpty(Username))
            {
                credential.UserName = Username;
            }
            else
            {
                credential.UserName = "******"; // Default user
            }

            if (!string.IsNullOrEmpty(Password))
            {
                credential.Password = Password;
            }
            else
            {
                credential.Password = "******";
            }
            credential.Resource = ResourceName;

            vault.Add(credential);
        }
        public static void SaveCredentialToLocker(MobileCredentials mobileCredentials)
        {
            // clean up
            var vault = new PasswordVault();
            try
            {
                var credentialList = vault.FindAllByResource(ResourceName);
                foreach (var passwordCredential in credentialList)
                {
                    vault.Remove(passwordCredential);
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {
            }

            var credential = new PasswordCredential
            {
                Resource = ResourceName,
                UserName = mobileCredentials.MobileNumber,
                Password = mobileCredentials.Password
            };

            vault.Add(credential);
        }
Beispiel #6
0
        /// <summary>
        /// Attempt to sign in to GitHub using the credentials supplied. 
        /// </summary>
        /// <param name="username">GitHub username</param>
        /// <param name="password">GitHub password</param>
        /// <param name="cached">Whether these credentials came from local storage</param>
        /// <returns>true if successful, false otherwise</returns>
        public async Task<string> Login(string username, string password, bool cached = false)
        {
            client.Credentials = new Credentials(username, password);
            try
            {
                //hacky way of determining whether the creds are correct
                await client.GitDatabase.Reference.Get("dhbrett", "Graffiti", "heads/master");
                //we haven't thrown so all good
                SignedIn = true;

                //these are new credentials, save them
                if (!cached)
                {
                    var pv = new PasswordVault();
                    pv.Add(new PasswordCredential { Resource = RESOURCE, UserName = username, Password = password });

                    localSettings.Values[USERNAME] = username;
                }

                return "pass";
            }
            catch(Exception e)
            {
                if (e.Message.Contains("two-factor"))
                {
                    return "tfa";
                }
                else if (cached)
                {
                    var pv = new PasswordVault();
                    pv.Remove(pv.Retrieve(RESOURCE, username));
                }
                return "fail";
            }
        }
        void ChangeUser_Click(object sender, RoutedEventArgs e)
        {
            Page outputFrame = (Page)rootPage.OutputFrame.Content;
            Page inputFrame  = (Page)rootPage.InputFrame.Content;

            try
            {
                Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                IReadOnlyList <PasswordCredential>         creds = vault.RetrieveAll();
                foreach (PasswordCredential c in creds)
                {
                    try
                    {
                        vault.Remove(c);
                    }
                    catch (Exception Error) // Stored credential was deleted
                    {
                        DebugPrint(Error.ToString());
                    }
                }
            }
            catch (Exception Error) // No stored credentials, so none to delete
            {
                DebugPrint(Error.ToString());
            }
            Reset1();
            CleanCombobox();
            CheckBox AuthenticationFailCheck = outputFrame.FindName("AuthenticationFailCheck") as CheckBox;

            AuthenticationFailCheck.IsChecked = false;
            TextBox WelcomeMessage = inputFrame.FindName("WelcomeMessage") as TextBox;

            WelcomeMessage.Text = "User has been changed, please resign in with new credentials, choose save and launch scenario again";
        }
Beispiel #8
0
        // Log the user in with specified provider (Microsoft Account or Facebook)
        private async Task AuthenticateAsync()
        {
            // Use the PasswordVault to securely store and access credentials.
            PasswordVault vault = new PasswordVault();
            PasswordCredential credential = null;

            try
            {
                // Try to get an existing credential from the vault.
                credential = vault.FindAllByResource(provider).FirstOrDefault();
            }
            catch (Exception)
            {
                // do nothing
            }

            if (credential != null)
            {
                // Create a user from the stored credentials.
                user = new MobileServiceUser(credential.UserName);
                credential.RetrievePassword();
                user.MobileServiceAuthenticationToken = credential.Password;

                // Set the user from the stored credentials.
                App.MobileService.CurrentUser = user;

                try
                {
                    // Try to return an item now to determine if the cached credential has expired.
                    await App.MobileService.GetTable<Event>().Take(1).ToListAsync();
                }
                catch (MobileServiceInvalidOperationException ex)
                {
                    if (ex.Response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                    {
                        // Remove the credential with the expired token.
                        vault.Remove(credential);
                        credential = null;
                    }
                }
            }
            else
            {
                try
                {
                    // Login with the identity provider.
                    user = await App.MobileService.LoginAsync(provider);

                    // Create and store the user credentials.
                    credential = new PasswordCredential(provider,
                        user.UserId, user.MobileServiceAuthenticationToken);
                    vault.Add(credential);
                }
                catch (MobileServiceInvalidOperationException ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                }
            }
        }
        /// <summary>
        /// Adds a credential to the credential locker.
        /// </summary>
        /// <param name="credential">The credential to be added.</param>
        public static void AddCredential(Credential credential)
        {
            if (credential == null || string.IsNullOrEmpty(credential.ServiceUri))
                return;

            var serverInfo = IdentityManager.Current.FindServerInfo(credential.ServiceUri);
            var host = serverInfo == null ? credential.ServiceUri : serverInfo.ServerUri;

            string passwordValue = null;  // value stored as password in the password locker
            string userName = null;
            var oAuthTokenCredential = credential as OAuthTokenCredential;
            var arcGISTokenCredential = credential as ArcGISTokenCredential;
            var arcGISNetworkCredential = credential as ArcGISNetworkCredential;
            if (oAuthTokenCredential != null)
            {
                userName = oAuthTokenCredential.UserName;
                if (!string.IsNullOrEmpty(oAuthTokenCredential.OAuthRefreshToken)) // refreshable OAuth token --> we store it so we'll be able to generate a new token from it
                    passwordValue = OAuthRefreshTokenPrefix + oAuthTokenCredential.OAuthRefreshToken;
                else if (!string.IsNullOrEmpty(oAuthTokenCredential.Token))
                    passwordValue = OAuthAccessTokenPrefix + oAuthTokenCredential.Token;
            }
            else if (arcGISTokenCredential != null)
            {
                userName = arcGISTokenCredential.UserName;
                if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(arcGISTokenCredential.Password)) // Token generated from an username/password --> store the password
                    passwordValue = PasswordPrefix + arcGISTokenCredential.Password;
            }
            else if (arcGISNetworkCredential != null)
            {
                // networkcredential: store the password
                if (arcGISNetworkCredential.Credentials != null)
                {
                    NetworkCredential networkCredential = arcGISNetworkCredential.Credentials.GetCredential(new Uri(host), "");
                    if (networkCredential != null && !string.IsNullOrEmpty(networkCredential.Password))
                    {
                        userName = networkCredential.UserName;
                        if (!string.IsNullOrEmpty(networkCredential.Domain))
                            userName = networkCredential.Domain + "\\" + userName;
                        passwordValue = NetworkCredentialPasswordPrefix + networkCredential.Password;
                    }
                }
            }

            // Store the value in the password locker
            if (passwordValue != null)
            {
                var passwordVault = new PasswordVault();
                var resource = ResourcePrefix + host;
                // remove previous resource stored for the same host
                try // FindAllByResource throws an exception when no pc are stored
                {
                    foreach (PasswordCredential pc in passwordVault.FindAllByResource(resource))
                        passwordVault.Remove(pc);
                }
                catch {}

                passwordVault.Add(new PasswordCredential(resource, userName, passwordValue));
            }
        }
        public static void ClearRoamedAccounts()
        {
            PasswordVault vault = new PasswordVault();

            foreach (var credential in vault.RetrieveAll())
            {
                vault.Remove(credential);
            }
        }
Beispiel #11
0
 public void RemoveAccessCode(string app, string userName)
 {
     var credential = GetCredential(app, userName);
     if (credential != null)
     {
         var vault = new PasswordVault();
         vault.Remove(credential);
     }
 }
 public void SaveLogin(string username, string password)
 {
     PasswordCredential pc;
     var passwordVault = new Windows.Security.Credentials.PasswordVault();
     var list = passwordVault.RetrieveAll().Where(i => String.Compare(i.Resource, RESOURCE) == 0);
     if((pc = list.FirstOrDefault(i => String.Compare(i.UserName, username) == 0)) != null)
     {
         passwordVault.Remove(pc);
         passwordVault.Add(new Windows.Security.Credentials.PasswordCredential(RESOURCE, username, password));
     }
     else if(list.Count() > 0)
     {
         foreach(var p in list)
         {
             passwordVault.Remove(p);
         }
     }
     passwordVault.Add(new Windows.Security.Credentials.PasswordCredential(RESOURCE, username, password));
 }
        public void UpdateCredentialsInVault(PasswordCredential passwordCredential)
        {
            var vault = new PasswordVault();
            var credentials = GetCredentialsFromVault(vault);
            if (credentials != null)
            {
                vault.Remove(credentials);
            }

            vault.Add(passwordCredential);
        }
Beispiel #14
0
		private async System.Threading.Tasks.Task AuthenticateAsync(String provider) {
			string message;

			// Use the PasswordVault to securely store and access credentials.
			PasswordVault vault = new PasswordVault();
			PasswordCredential credential = null;

			while (credential == null) {
				try {
					// Try to get an existing credential from the vault.
					credential = vault.FindAllByResource(provider).FirstOrDefault();
				} catch (Exception) {
					// When there is no matching resource an error occurs, which we ignore.
				}

				if (credential != null) {
					// Create a user from the stored credentials.
					_user = new MobileServiceUser(credential.UserName);
					credential.RetrievePassword();
					_user.MobileServiceAuthenticationToken = credential.Password;

					// Set the user from the stored credentials.
					App.MobileService.CurrentUser = _user;

					try {
						// Try to return an item now to determine if the cached credential has expired.
						await App.MobileService.GetTable<TrainingItem>().Take(1).ToListAsync();
					} catch (MobileServiceInvalidOperationException ex) {
						if (ex.Response.StatusCode == System.Net.HttpStatusCode.Unauthorized) {
							// Remove the credential with the expired token.
							vault.Remove(credential);
							credential = null;
							continue;
						}
					}
				} else {
					try {
						// Login with the identity provider.
						_user = await App.MobileService.LoginAsync(provider);

						// Create and store the user credentials.
						credential = new PasswordCredential(provider, _user.UserId, _user.MobileServiceAuthenticationToken);
						vault.Add(credential);
					} catch (MobileServiceInvalidOperationException ex) {
						message = "You must log in. Login Required";
					}
				}

				message = string.Format("You are now logged in - {0}", _user.UserId);
				var dialog = new MessageDialog(message);
				dialog.Commands.Add(new UICommand("OK"));
				await dialog.ShowAsync();
			}
		}
Beispiel #15
0
        private void SettingsCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
        {
            SettingsCommand about_cmd = new SettingsCommand("about", "About", (x) =>
            {
                _settingsPopup = new Popup();
                _settingsPopup.Closed += OnPopupClosed;
                Window.Current.Activated += OnWindowActivated;
                _settingsPopup.IsLightDismissEnabled = true;
                _settingsPopup.Width = _settingsWidth;
                _settingsPopup.Height = _windowBounds.Height;

                SettingsAboutView mypane = new SettingsAboutView();
                //SimpleSettingsNarrow mypane = new SimpleSettingsNarrow();
                mypane.Width = _settingsWidth;
                mypane.Height = _windowBounds.Height;

                _settingsPopup.Child = mypane;
                _settingsPopup.SetValue(Canvas.LeftProperty, _windowBounds.Width - _settingsWidth);
                _settingsPopup.SetValue(Canvas.TopProperty, 0);
                _settingsPopup.IsOpen = true;
            });

            args.Request.ApplicationCommands.Add(about_cmd);

            SettingsCommand logout_cmd = new SettingsCommand("logout", "Log out", (x) =>
            {
                var vault = new PasswordVault();
                vault.Remove(vault.Retrieve("Sovok.tv WinApp", App.ViewModel.UserAccount.login));
                bool nav = Frame.Navigate(typeof(Login));
                App.ViewModel = new Model.MainViewModel();
            });

            args.Request.ApplicationCommands.Add(logout_cmd);

            SettingsCommand settings_cmd = new SettingsCommand("settings", "Settings", (x) =>
            {
                _settingsPopup = new Popup();
                _settingsPopup.Closed += OnPopupClosed;
                Window.Current.Activated += OnWindowActivated;
                _settingsPopup.IsLightDismissEnabled = true;
                _settingsPopup.Width = _settingsWidth;
                _settingsPopup.Height = _windowBounds.Height;

                SettingsView mypane = new SettingsView();
                mypane.Width = _settingsWidth;
                mypane.Height = _windowBounds.Height;

                _settingsPopup.Child = mypane;
                _settingsPopup.SetValue(Canvas.LeftProperty, _windowBounds.Width - _settingsWidth);
                _settingsPopup.SetValue(Canvas.TopProperty, 0);
                _settingsPopup.IsOpen = true;
            });
            args.Request.ApplicationCommands.Add(settings_cmd);
        }
 private static void RemoveAllCredentialsByResource(string resource, PasswordVault vault) {
     try {
         // Remove the old credentials for this resource
         var oldCredentials = vault.FindAllByResource(resource);
         foreach (var oldCredential in oldCredentials) {
             vault.Remove(oldCredential);
         }
     }
     catch (Exception) {
     } // FindAllByResource throws Exception if nothing stored for that resource
 }
 public static void RemoveCredentials()
 {
     var vault = new PasswordVault();
     try
     {
         var credentialList = vault.FindAllByResource(resourceName);
         foreach (var credential in credentialList)
             vault.Remove(credential);
         ServiceUser = null;
     }
     catch { }
 }
 /// <summary>
 /// Clears PasswordVault of any saved password
 /// </summary>
 public static void ClearAllSavedPasswords()
 {
     try
     {
         var vault = new Windows.Security.Credentials.PasswordVault();
         foreach (var p in vault.RetrieveAll())
         {
             vault.Remove(p);
         }
     }
     catch (Exception) { }
 }
Beispiel #19
0
        public static void RemoveCredential()
        {
            var pcList = RetrieveAllCredential();
            if (pcList == null)
                return;

            PasswordVault vault = new PasswordVault();
            foreach (var pc in pcList)
            {
                vault.Remove(pc);
            }
        }
        public void SaveIfttt(string key)
        {
            if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key));

            var vault = new PasswordVault();

            foreach (var item in vault.RetrieveAll().Where(v => v.Resource == "ifttt"))
            {
                vault.Remove(item);
            }

            vault.Add(new PasswordCredential("ifttt", "key", key));
        }
 /// <summary>
 ///     Removes the password from the secure storage.
 /// </summary>
 public void RemovePassword()
 {
     // If there where no element to remove it will throw a com exception who we handle.
     try
     {
         var vault = new PasswordVault();
         var passwordCredential = vault.Retrieve(Package.Current.Id.Name, PASSWORD_KEY);
         vault.Remove(passwordCredential);
     }
     catch (Exception)
     {
     }
 }
 public void DeleteSavedCredentials()
 {
     try
     {
         var passwordVault = new PasswordVault();
         var credentials = passwordVault.FindAllByResource(PasswordVaultResourceName);
         if (credentials != null && credentials.Any())
         {
             passwordVault.Remove(credentials[0]);
         }
     }
     catch (Exception) { }
 }
        public static async Task ClearCurrentUser()
        {
            string sessionKey = CurrentUser.SessionKey;
            await UsersPersister.Logout(sessionKey);
            var vault = new PasswordVault();
            vault.Remove(vault.Retrieve(UserCredentialsToken, CurrentUser.Username));


            localSettings.Values["ProfilePictureUrl"] = "";
            localSettings.Values["FirstName"] = "";
            localSettings.Values["LastName"] = "";
            localSettings.Values["Reputation"] = "";
        }
        private void ButtonDeletePIN_Click(object sender, RoutedEventArgs e)
        {
            var    vault           = new Windows.Security.Credentials.PasswordVault();
            string resourceName    = "Mastercond.Documents";
            string defaultUserName = "******";
            string password        = MakeCryptSHA512(EnterPINPasswordBox.Password.ToString());

            try
            {
                vault.Remove(new Windows.Security.Credentials.PasswordCredential(resourceName, defaultUserName, password));
                StatusFile.Text = "ПИН-код успешно удален. При следующем входе в приложение Вы сможете установить новый ПИН.";
            }
            catch { StatusFile.Text = "Не удалось выполнить сброс ПИН-кода. Проверьте правильность введенного Вами ПИН-кода."; }
        }
Beispiel #25
0
 public static void SetNotifierCredential(string username, string password)
 {
     var vault = new PasswordVault();
     var credentials = vault.RetrieveAll();
     foreach (var credential in credentials)
     {
         if (credential.Resource == "NOTCRED" && credential.UserName == username)
         {
             vault.Remove(credential);
         }
     }
     if (password != null)
     {
         vault.Add(new PasswordCredential("NOTCRED", username, password));
     }
 }
 /// <summary>
 /// Clears any saved password for the given database
 /// </summary>
 /// <param name="databaseName"></param>
 public static void ClearSavedPasswordForDatabase(string databaseName)
 {
     // No need to try to remove any saved password if WIndows Hello is not enabled
     if (SettingsViewModel.Instance.WindowsHelloEnabled)
     {
         try
         {
             var vault = new Windows.Security.Credentials.PasswordVault();
             foreach (var p in vault.FindAllByResource(databaseName))
             {
                 vault.Remove(p);
             }
         }
         catch (Exception) { }
     }
 }
Beispiel #27
0
		private void Clear()
		{
			try
			{
				PasswordVault vault = new PasswordVault();
				var items = vault.FindAllByResource(AppResourceName);
				foreach (var item in items)
				{
					vault.Remove(item);
				}
			}
			// ReSharper disable once EmptyGeneralCatchClause
			catch (Exception)
			{
			}
		}
Beispiel #28
0
		public static async Task LogOff() {
			var vault = new PasswordVault();
			const string vaultResource = "S2M";

			var credentialList = vault.FindAllByResource(vaultResource);

			if (credentialList.Any()) {
				var credentials = credentialList.First();
				var username = credentials.UserName;
				var password = vault.Retrieve(vaultResource, username).Password;

				vault.Remove(new PasswordCredential(vaultResource, username, password));
			}

			await Common.StorageService.DeleteObjectAsync("Profile");
		}
        private bool SaveSettings(string user, string password, string host, string port, Scheme scheme)
        {
            var vault = new PasswordVault();
            foreach (var pwdCredential in vault.RetrieveAll())
            {
                vault.Remove(pwdCredential);
            }

            vault.Add(new PasswordCredential(ResourceName, user, password));

            var res = vault.FindAllByUserName(user);
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
            localSettings.Values["host"] = host;
            localSettings.Values["scheme"] = scheme.ToString();
            localSettings.Values["port"] = port.ToString();       
            MainPage.SplunkService = null;
            return true;
        }
        public static void Clear()
        {
            var vault = new PasswordVault();

            try
            {
                IReadOnlyList<PasswordCredential> creds = vault.FindAllByResource("redditAuth");
                if (creds == null) return;
                foreach (var cred in creds)
                {
                    vault.Remove(cred);
                }
            }
            catch (Exception)
            {
                // The password vault is mildly retarded.
            }
        }
Beispiel #31
0
        internal override async Task SignOut()
        {
            try
            {
                var vault = new PasswordVault();

                var vidyanoCredentials = vault.FindAllByResource(vaultCredentialsName).FirstOrDefault();
                if (vidyanoCredentials != null)
                    vault.Remove(vidyanoCredentials);
            }
            catch { }

            await Vidyano.View.Controls.AppBarUserButton.RemoveUserPicture();

            var rootFrame = (Frame)Window.Current.Content;
            while (rootFrame.CanGoBack)
                rootFrame.GoBack();
        }
        public void SaveFifthplay(string username, string password)
        {
            if (username == null) throw new ArgumentNullException(nameof(username));
            if (password == null) throw new ArgumentNullException(nameof(password));

            var vault = new PasswordVault();

            foreach (var item in vault.RetrieveAll().Where(v => v.Resource == "fifthplay"))
            {
                vault.Remove(item);
            }

            vault.Add(new PasswordCredential("fifthplay", username, password));

            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("fifthplay-username"))
                ApplicationData.Current.LocalSettings.Values.Add("fifthplay-username", username);
            else
                ApplicationData.Current.LocalSettings.Values["fifthplay-username"] = username;
        }
Beispiel #33
0
        private void Remover_Button_Click(object sender, RoutedEventArgs e)
        {
            var vault = new PasswordVault();
            if (!string.IsNullOrWhiteSpace(RecursoTextBox.Text))
            {
                try
                {
                    var credenciais = vault.FindAllByResource(RecursoTextBox.Text);
                    var credencial = credenciais.First();
                    vault.Remove(credencial);

                    MensagemTextBlock.Text = string.Empty;
                }
                catch (Exception)
                {
                    MensagemTextBlock.Text = "Credencial não encontrada";
                }
            }
        }
Beispiel #34
0
        private void Launch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Page outputFrame = (Page)rootPage.OutputFrame.Content;
                Page inputFrame  = (Page)rootPage.InputFrame.Content;
                Reset1();
                CheckBox AuthenticationFailCheck = outputFrame.FindName("AuthenticationFailCheck") as CheckBox;
                TextBox  WelcomeMessage          = inputFrame.FindName("WelcomeMessage") as TextBox;
                if (AuthenticationFailCheck.IsChecked == true)
                {
                    WelcomeMessage.Text = "Blocked";
                }
                else
                {
                    PasswordCredential cred = new PasswordCredential();
                    Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                    IReadOnlyList <PasswordCredential>         Creds = vault.FindAllByResource("Scenario 1");

                    foreach (PasswordCredential c in Creds)
                    {
                        try
                        {
                            vault.Remove(c);
                        }
                        catch (Exception Error) // Stored credential was deleted
                        {
                            DebugPrint(Error.ToString());
                        }
                    }

                    WelcomeMessage.Text = "Scenario is ready, please sign in";
                }
            }
            catch (Exception Error)
            {
                //
                // Bad Parameter, Machine infor Unavailable errors are to be handled here.
                //
                DebugPrint(Error.ToString());
            }
        }
 void Scenario4Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Windows.Security.Credentials.PasswordVault v     = new Windows.Security.Credentials.PasswordVault();
         IReadOnlyList <PasswordCredential>         creds = v.RetrieveAll();
         DeleteSummary.Text = "Number of credentials deleted: " + creds.Count;
         foreach (PasswordCredential c in creds)
         {
             v.Remove(c);
         }
         // GetAll is a snapshot in time, so to reflect the updated vault, get all credentials again
         creds = v.RetrieveAll();
         // The credentials should now be empty
     }
     catch (Exception Error)
     {
         DebugPrint(Error.ToString());
     }
 }
        async private void delete(object sender, RoutedEventArgs e)
        {
            PasswordVault vault = new PasswordVault();

            foreach (var cred in vault.RetrieveAll())
            {
                cred.RetrievePassword();
                if (cred.Resource == Resource.Text || cred.UserName == user.Text || cred.Password == pwd.Password)
                {
                    var vaul = new Windows.Security.Credentials.PasswordVault();
                    vaul.Remove(new Windows.Security.Credentials.PasswordCredential(cred.Resource, cred.UserName, cred.Password));
                    var dialog = new MessageDialog("Done!!!!");
                    await dialog.ShowAsync();
                }

                else
                {
                    var dialog = new MessageDialog("Credentials Does Not Exist");
                    await dialog.ShowAsync();
                }
            }
        }
Beispiel #37
0
        private void Reset_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                TextBox InputResourceValue = rootPage.FindName("InputResourceValue") as TextBox;
                InputResourceValue.Text = "";
                TextBox InputUserNameValue = rootPage.FindName("InputUserNameValue") as TextBox;
                InputUserNameValue.Text = "";
                PasswordBox InputPasswordValue = rootPage.FindName("InputPasswordValue") as PasswordBox;
                InputPasswordValue.Password = "";
                TextBox ErrorMessage = rootPage.FindName("ErrorMessage") as TextBox;
                ErrorMessage.Text = "";

                Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                IReadOnlyList <PasswordCredential>         creds = vault.RetrieveAll();
                foreach (PasswordCredential c in creds)
                {
                    try
                    {
                        vault.Remove(c);
                    }
                    catch (Exception Error) // Stored credential was deleted
                    {
                        DebugPrint(Error.ToString());
                    }
                }

                DebugPrint("Scenario has been reset. All credentials are removed.");
            }
            catch (Exception Error)
            {
                //
                // Bad Parameter, Machine infor Unavailable errors are to be handled here.
                //
                DebugPrint(Error.Message);
            }
        }
        public override async void LoginAsync()
        {
            string message;
            // This sample uses the Facebook provider.
            var provider = "AAD";

            // Use the PasswordVault to securely store and access credentials.
            PasswordVault vault = new PasswordVault();
            PasswordCredential credential = null;

            while (credential == null)
            {
                try
                {
                    // Try to get an existing credential from the vault.
                    credential = vault.FindAllByResource(provider).FirstOrDefault();
                }
                catch (Exception)
                {
                    // When there is no matching resource an error occurs, which we ignore.
                }

                if (credential != null)
                {
                    // Create a user from the stored credentials.
                    user = new MobileServiceUser(credential.UserName);
                    credential.RetrievePassword();
                    user.MobileServiceAuthenticationToken = credential.Password;

                    // Set the user from the stored credentials.
                    App.MobileService.CurrentUser = user;

                    try
                    {
                        // Try to return an item now to determine if the cached credential has expired.
                        await App.MobileService.InvokeApiAsync("custom", HttpMethod.Get, new Dictionary<string,string>() );                        
                    }
                    catch (MobileServiceInvalidOperationException ex)
                    {
                        if (ex.Response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                        {
                            // Remove the credential with the expired token.
                            vault.Remove(credential);
                            credential = null;
                            continue;
                        }
                    }
                }
                else
                {
                    try
                    {
                        // Login with the identity provider.
                        user = await App.MobileService
                            .LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);

                        // Create and store the user credentials.
                        credential = new PasswordCredential(provider,
                            user.UserId, user.MobileServiceAuthenticationToken);
                        vault.Add(credential);
                    }
                    catch (MobileServiceInvalidOperationException ex)
                    {
                        message = "You must log in. Login Required";
                    }
                }
                message = string.Format("You are now logged in - {0}", user.UserId);
                var dialog = new MessageDialog(message);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
                IsLoggedIn = true;
            }
        }
 private void ClearVault()
 {
     try
     {
         var vault = new PasswordVault();
         var cred = vault.Retrieve(_resourceName, "token");
         vault.Remove(cred);
     }
     catch { }
 }
Beispiel #40
0
        private void Reset_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                TextBox InputResourceValue = rootPage.FindName("InputResourceValue") as TextBox;
                InputResourceValue.Text = "";
                TextBox InputUserNameValue = rootPage.FindName("InputUserNameValue") as TextBox;
                InputUserNameValue.Text = "";
                PasswordBox InputPasswordValue = rootPage.FindName("InputPasswordValue") as PasswordBox;
                InputPasswordValue.Password = "";
                TextBox ErrorMessage = rootPage.FindName("ErrorMessage") as TextBox;
                ErrorMessage.Text = "";

                Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                IReadOnlyList<PasswordCredential> creds = vault.RetrieveAll();
                foreach (PasswordCredential c in creds)
                {
                    try
                    {
                        vault.Remove(c);
                    }
                    catch (Exception Error) // Stored credential was deleted
                    {
                        DebugPrint(Error.ToString());
                    }
                }

                DebugPrint("Scenario has been reset. All credentials are removed.");
            }
            catch (Exception Error)
            {
                //
                // Bad Parameter, Machine infor Unavailable errors are to be handled here.
                //
                DebugPrint(Error.Message);
            }
        }                
Beispiel #41
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            TextBox InputResourceValue = rootPage.FindName("InputResourceValue") as TextBox;
            TextBox InputUserNameValue = rootPage.FindName("InputUserNameValue") as TextBox;
            String result = "";
            if (InputResourceValue.Text == "" || InputUserNameValue.Text == "")
            {
                DebugPrint("Inputs are missing. Resource and Username are required.");
            }
            else
            {
                try
                {
                    //
                    //this is the code to remove a credentialt from PasswordVault by supplying resource or username
                    //
                    Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                    PasswordCredential cred = vault.Retrieve(InputResourceValue.Text, InputUserNameValue.Text);
                    vault.Remove(cred);
                    result = "Credential removed successfully. Resource: " + InputResourceValue.Text + " Username: "******".";
                    DebugPrint(result.ToString());
                }
                catch (Exception Error) // No stored credentials, so none to delete
                {
                    DebugPrint(Error.Message);
                }
            }

        }