当前位置: 首页>>代码示例>>C#>>正文


C# PasswordVault.Remove方法代码示例

本文整理汇总了C#中Windows.Security.Credentials.PasswordVault.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# PasswordVault.Remove方法的具体用法?C# PasswordVault.Remove怎么用?C# PasswordVault.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Security.Credentials.PasswordVault的用法示例。


在下文中一共展示了PasswordVault.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LogoutAsync

        // 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;

        }
开发者ID:karolzak,项目名称:XAML-Blend-Tutorial,代码行数:55,代码来源:MainPageViewModel.cs

示例2: SaveCredentialToLocker

        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);
        }
开发者ID:davidvidmar,项目名称:MobilnaPoraba,代码行数:26,代码来源:Credentials.cs

示例3: Login

        /// <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";
            }
        }
开发者ID:DHBrett,项目名称:Graffiti,代码行数:42,代码来源:GitHub.cs

示例4: AddCredential

        /// <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));
            }
        }
开发者ID:skudev,项目名称:arcgis-toolkit-dotnet,代码行数:63,代码来源:CredentialManager.cs

示例5: AuthenticateAsync

        // 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);
                }
            }
        }
开发者ID:stephendj,项目名称:evenue,代码行数:60,代码来源:LoginPage.xaml.cs

示例6: ClearRoamedAccounts

        public static void ClearRoamedAccounts()
        {
            PasswordVault vault = new PasswordVault();

            foreach (var credential in vault.RetrieveAll())
            {
                vault.Remove(credential);
            }
        }
开发者ID:mbmccormick,项目名称:Authenticator,代码行数:9,代码来源:AccountManager.cs

示例7: RemoveAccessCode

 public void RemoveAccessCode(string app, string userName)
 {
     var credential = GetCredential(app, userName);
     if (credential != null)
     {
         var vault = new PasswordVault();
         vault.Remove(credential);
     }
 }
开发者ID:dkackman,项目名称:DeviceOAuth2,代码行数:9,代码来源:VaultWrapper.cs

示例8: SaveLogin

 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));
 }
开发者ID:holtsoftware,项目名称:bearded-avenger,代码行数:19,代码来源:WindowsLoginStore.cs

示例9: SettingsCommandsRequested

        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);
        }
开发者ID:legator,项目名称:SovokTV,代码行数:54,代码来源:PlayerPage.xaml.cs

示例10: UpdateCredentialsInVault

        public void UpdateCredentialsInVault(PasswordCredential passwordCredential)
        {
            var vault = new PasswordVault();
            var credentials = GetCredentialsFromVault(vault);
            if (credentials != null)
            {
                vault.Remove(credentials);
            }

            vault.Add(passwordCredential);
        }
开发者ID:valentingovo,项目名称:SubSonic8,代码行数:11,代码来源:SettingsHelper.cs

示例11: AuthenticateAsync

		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();
			}
		}
开发者ID:fxlemire,项目名称:princeton15,代码行数:54,代码来源:LoginPage.xaml.cs

示例12: RemoveAllCredentialsByResource

 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
 }
开发者ID:ronlemire2,项目名称:PrismRT-CodeGen-v2.1,代码行数:11,代码来源:RoamingCredentialStore.cs

示例13: RemoveCredentials

 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 { }
 }
开发者ID:Grobi1,项目名称:MyAnimeList-Universal,代码行数:12,代码来源:UserManager.cs

示例14: RemoveCredential

        public static void RemoveCredential()
        {
            var pcList = RetrieveAllCredential();
            if (pcList == null)
                return;

            PasswordVault vault = new PasswordVault();
            foreach (var pc in pcList)
            {
                vault.Remove(pc);
            }
        }
开发者ID:huangjia2107,项目名称:Joke,代码行数:12,代码来源:FileHelper.cs

示例15: RemovePassword

 /// <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)
     {
     }
 }
开发者ID:Rumpel78,项目名称:MoneyFox.Windows,代码行数:16,代码来源:PasswordStorage.cs


注:本文中的Windows.Security.Credentials.PasswordVault.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。