public void Remove(string key) { var vault = new Windows.Security.Credentials.PasswordVault(); var passwordCredential = vault.Retrieve(Windows.ApplicationModel.Package.Current.Id.Name, key); vault.Remove(passwordCredential); }
private static void _AddOrUpdateAccount(string mailAddress, string password) { var id = mailAddress; if (String.IsNullOrWhiteSpace(mailAddress) || String.IsNullOrWhiteSpace(password)) { throw new Exception(); } var vault = new Windows.Security.Credentials.PasswordVault(); try { var credential = vault.Retrieve(nameof(HohoemaApp), id); vault.Remove(credential); } catch { } { var credential = new Windows.Security.Credentials.PasswordCredential(nameof(HohoemaApp), id, password); vault.Add(credential); } }
private void AddOrUpdateWindowsCredential(UserCredential existingCredential, string password) { var passwordVault = new Windows.Security.Credentials.PasswordVault(); try { var windowsCredentials = passwordVault.FindAllByResource("Baconography"); var matchingWindowsCredential = windowsCredentials.FirstOrDefault(credential => string.Compare(credential.UserName, existingCredential.Username, StringComparison.CurrentCultureIgnoreCase) == 0); if (matchingWindowsCredential != null) { matchingWindowsCredential.RetrievePassword(); if (matchingWindowsCredential.Password != password) { passwordVault.Remove(matchingWindowsCredential); } else { passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } } else { passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } } catch { passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } }
private static void _AddOrUpdateAccount(string mailAddress, string password) { var id = mailAddress; if (String.IsNullOrWhiteSpace(mailAddress) || String.IsNullOrWhiteSpace(password)) { throw new Models.Infrastructure.HohoemaExpception(); } var vault = new Windows.Security.Credentials.PasswordVault(); try { var credential = vault.Retrieve(AccountResrouceKey, id); vault.Remove(credential); } catch { } { var credential = new Windows.Security.Credentials.PasswordCredential(AccountResrouceKey, id, password); vault.Add(credential); } }
public void LogOut() { var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.FindAllByResource("Modern Player Manager"); var credential = credentialList[0]; vault.Remove(credential); (Window.Current.Content as Frame)?.Navigate(typeof(LoginPage)); }
public void Delete(string key) { var vault = new Windows.Security.Credentials.PasswordVault(); var resources = vault.FindAllByResource(key); if (resources.Any()) { vault.Remove(resources.First()); } }
public void SetSecured(string id, string value, string clientId, string service, string sharedGroup) { var vault = new Windows.Security.Credentials.PasswordVault(); try { var pass = vault.Retrieve(ResourceIdentifier, $"{clientId}-{id}-{service}"); if (pass != null) vault.Remove(pass); } catch { } vault.Add(new Windows.Security.Credentials.PasswordCredential(ResourceIdentifier, $"{clientId}-{id}-{service}", value)); }
public void RemoveRecentLoginAccount() { var vault = new Windows.Security.Credentials.PasswordVault(); try { var oldItems = vault.FindAllByResource(nameof(Uncord)); foreach (var vaultItem in oldItems) { vault.Remove(vaultItem); } oldItems = null; } catch { } }
public void LogOutVk() { var vault = new Windows.Security.Credentials.PasswordVault(); vault.Remove(vault.Retrieve("VkApp", ApplicationService.Instance.Settings.UserId)); this._vkontakte.AccessToken.Token = null; this._vkontakte.AccessToken.UserId = null; ApplicationService.Instance.Settings.AccessToken = null; ApplicationService.Instance.Settings.UserId = null; ApplicationService.Instance.Settings.Save(); Messenger.Default.Send <LoginMessage>(new LoginMessage { Type = LoginType.LogOut, IsSuccess = true }); }
private async void Button_Click(object sender, RoutedEventArgs e) { try { await MainModel.Current.Save(); var vault = new Windows.Security.Credentials.PasswordVault(); foreach (var record in vault.FindAllByResource("LearnTHU")) { vault.Remove(record); } } finally { ((Frame)Window.Current.Content).Navigate(typeof(Login)); } }
public void Delete(string key) { var vault = new Windows.Security.Credentials.PasswordVault(); try { var resources = vault.FindAllByResource(key); if (resources.Any()) { vault.Remove(resources.First()); } } catch (System.Runtime.InteropServices.COMException) { /* try to remove something that isn't there...not gonna throw an exception */ } }
public async Task RemoveStoredCredential(string username) { var userInfoDb = await GetUserInfoDB(); try { //go find the one we're updating and actually do it var userCredentialsCursor = await userInfoDb.SelectAsync(userInfoDb.GetKeys().First(), "credentials", DBReadFlags.AutoLock); if (userCredentialsCursor != null) { using (userCredentialsCursor) { do { var credential = JsonConvert.DeserializeObject <UserCredential>(userCredentialsCursor.GetString()); if (credential.Username == username) { await userCredentialsCursor.DeleteAsync(); } } while (await userCredentialsCursor.MoveNextAsync()); } } } catch { //let it fail } var passwordVault = new Windows.Security.Credentials.PasswordVault(); try { var windowsCredentials = passwordVault.FindAllByResource("Baconography"); var matchingWindowsCredential = windowsCredentials.FirstOrDefault(windowsCredential => string.Compare(windowsCredential.UserName, username, StringComparison.CurrentCultureIgnoreCase) == 0); if (matchingWindowsCredential != null) { passwordVault.Remove(matchingWindowsCredential); } } catch { } }
private string CheckForValidToken() { var vault = new Windows.Security.Credentials.PasswordVault(); try { var cred = vault.Retrieve(IdentityManager.AccessControlNamespace, Name); IsActive = !IsExpired(cred.Password); if (!IsActive) vault.Remove(cred); return cred.Password; } catch { IsActive = false; return string.Empty; } }
private async void user_cancel_Click(object sender, RoutedEventArgs e) { var dialog = new ContentDialog(); dialog.Title = "0.0"; dialog.Content = "亲,真的要取消已绑定帐号吗?"; dialog.PrimaryButtonText = "确定"; dialog.PrimaryButtonClick += (_s, _e) => { var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.FindAllByResource(resourceName); foreach (var item in credentialList) { vault.Remove(item); } this.Frame.Navigate(typeof(Volunteer_LoginPage)); }; dialog.SecondaryButtonText = "取消"; dialog.SecondaryButtonClick += (_s, _e) => { }; await dialog.ShowAsync(); }
private void logoutButton_Click(object sender, RoutedEventArgs e) { try { Frame rootFrame = Window.Current.Content as Frame; if (rootFrame != null) { GnarlyClient.Instance.Disconnect(); Windows.Security.Credentials.PasswordVault valut = new Windows.Security.Credentials.PasswordVault(); foreach (var c in valut.RetrieveAll()) { valut.Remove(c); } rootFrame.Navigate(typeof(LoginSelection)); } } catch (Exception exception) { App.LogUnhandledError(exception); } }
private async void SavePodioCredentials(object sender, RoutedEventArgs e) { try { var vault = new Windows.Security.Credentials.PasswordVault(); try { var existingCredentials = vault.FindAllByResource("nyltformcapture"); foreach (var credential in existingCredentials) { vault.Remove(credential); } } catch { } vault.Add(new Windows.Security.Credentials.PasswordCredential( "nyltformcapture", AppID.Text, AppSecret.Password)); CredentialsSaved(); } catch (Exception ex) { await Notify(ex.Message); } }
private static bool _RemoveAccount(string mailAddress) { var id = mailAddress; if (String.IsNullOrWhiteSpace(mailAddress)) { return(false); } var vault = new Windows.Security.Credentials.PasswordVault(); try { var credential = vault.Retrieve(nameof(HohoemaApp), id); vault.Remove(credential); return(true); } catch { } return(false); }
private void AddOrUpdateRecentLoginAccount(string mail, string password) { try { var vault = new Windows.Security.Credentials.PasswordVault(); try { var oldItems = vault.FindAllByResource(nameof(Uncord)); foreach (var vaultItem in oldItems) { vault.Remove(vaultItem); } oldItems = null; } catch { } vault.Add(new Windows.Security.Credentials.PasswordCredential( nameof(Uncord), mail, password)); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
private void AddOrUpdateWindowsCredential(UserCredential existingCredential, string password) { var passwordVault = new Windows.Security.Credentials.PasswordVault(); try { var windowsCredentials = passwordVault.FindAllByResource("Baconography"); var matchingWindowsCredential = windowsCredentials.FirstOrDefault(credential => string.Compare(credential.UserName, existingCredential.Username, StringComparison.CurrentCultureIgnoreCase) == 0); if (matchingWindowsCredential != null) { matchingWindowsCredential.RetrievePassword(); if (matchingWindowsCredential.Password != password) { passwordVault.Remove(matchingWindowsCredential); } else passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } else passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } catch { passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("Baconography", existingCredential.Username, password)); } }
public async Task RemoveStoredCredential(string username) { var userInfoDb = await GetUserInfoDB(); try { //go find the one we're updating and actually do it var userCredentialsCursor = await userInfoDb.SelectAsync(userInfoDb.GetKeys().First(), "credentials", DBReadFlags.AutoLock); if (userCredentialsCursor != null) { using (userCredentialsCursor) { do { var credential = JsonConvert.DeserializeObject<UserCredential>(userCredentialsCursor.GetString()); if (credential.Username == username) { await userCredentialsCursor.DeleteAsync(); } } while (await userCredentialsCursor.MoveNextAsync()); } } } catch { //let it fail } var passwordVault = new Windows.Security.Credentials.PasswordVault(); try { var windowsCredentials = passwordVault.FindAllByResource("Baconography"); var matchingWindowsCredential = windowsCredentials.FirstOrDefault(windowsCredential => string.Compare(windowsCredential.UserName, username, StringComparison.CurrentCultureIgnoreCase) == 0); if (matchingWindowsCredential != null) { passwordVault.Remove(matchingWindowsCredential); } } catch { } }
public async Task <T> IdentifyAsync <T>(AuthenticationProvider provider, ACSProvider ACSProvider = null) where T : Identity, new() { var vault = new Windows.Security.Credentials.PasswordVault(); try { var tok = vault.Retrieve(AccessControlNamespace, provider.ToString()); if (IsExpired(tok.Password)) { vault.Remove(tok); } else { return(new T() { Token = tok.Password, Success = true, Provider = provider }); } } catch (Exception ex) { } string LoginUrl = ""; string BouncerEndUrl = ""; switch (provider) { case AuthenticationProvider.AzureControlService: if (ACSProvider != null) { LoginUrl = ACSProvider.LoginUrl; } else { if (string.IsNullOrEmpty(AccessControlNamespace)) { throw new ArgumentNullException("AccessControlNamespace"); } if (string.IsNullOrEmpty(Realm)) { throw new ArgumentNullException("Realm"); } if (string.IsNullOrEmpty(BouncerReplyUrl)) { throw new ArgumentNullException("BouncerReplyUrl"); } LoginUrl = string.Format(ACS_Login_Feed, AccessControlNamespace, Realm, BouncerReplyUrl); } BouncerEndUrl = BouncerReplyUrl + "end"; break; case AuthenticationProvider.Facebook: LoginUrl = string.Format(Facebook_Login_Feed, Uri.EscapeDataString(FacebookApplicationID), Uri.EscapeDataString(Facebook_LoginSucces)); BouncerEndUrl = Facebook_LoginSucces; break; } return(await WebAuthenticationBroker.AuthenticateAsync( WebAuthenticationOptions.None, new Uri(LoginUrl), new Uri(BouncerEndUrl)).AsTask <WebAuthenticationResult>() .ContinueWith <T>(t => { var response = t.Result; if (!t.IsFaulted && (response.ResponseStatus == WebAuthenticationStatus.Success)) { string token = response.ResponseData; // response.ResponseData.Substring(response.ResponseData.IndexOf('=') + 1); token = token.Replace(BouncerEndUrl, "").Substring(1); //Assume that the url is the BouncerEndUrl + '#' / '?' + claims. if (provider == AuthenticationProvider.Facebook) { var idx = token.IndexOf("&expires_in="); var time = int.Parse(token.Substring(idx + 12)); token = token.Insert(idx, string.Format("&ExpiresOn={0}", (int)DateTime.UtcNow.Add(TimeSpan.FromSeconds(time)).Subtract(Epoch).TotalSeconds)); } if (UsePasswordVault) { var cred = new Windows.Security.Credentials.PasswordCredential(AccessControlNamespace, provider.ToString(), token); new Windows.Security.Credentials.PasswordVault().Add(cred); } return new T() { Token = token, Success = true, Provider = provider }; } else { return new T() { UnSuccessReason = response.ResponseStatus.ToString(), Success = false, Provider = provider } }; })); }
private async void ClearButton_Click(object sender, RoutedEventArgs e) { var dig = new MessageDialog("若应用无法使用,请尝试清除数据,清除数据后会应用将返回登陆界面。\n\n是否继续?", "警告"); var btnOk = new UICommand("是"); dig.Commands.Add(btnOk); var btnCancel = new UICommand("否"); dig.Commands.Add(btnCancel); var result = await dig.ShowAsync(); if (null != result && result.Label == "是") { appSetting.Values.Clear(); DelectRemind(); try { var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.FindAllByResource(resourceName); foreach (var item in credentialList) { vault.Remove(item); } } catch { } appSetting.Values["CommunityPerInfo"] = false; appSetting.Values["isUseingBackgroundTask"] = false; IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder; IStorageFile storageFileWR = await applicationFolder.CreateFileAsync("kb", CreationCollisionOption.OpenIfExists); try { await storageFileWR.DeleteAsync(); if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList")) { if (JumpList.IsSupported()) DisableSystemJumpListAsync(); } } catch (Exception) { Debug.WriteLine("个人 -> 切换账号删除课表数据异常"); } try { await storageFileWR.DeleteAsync(); } catch (Exception error) { Debug.WriteLine(error.Message); Debug.WriteLine("设置 -> 重置应用异常"); } //Application.Current.Exit(); Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(LoginPage)); } else if (null != result && result.Label == "否") { } }
private async void SwitchAppBarButton_Click(object sender, RoutedEventArgs e) { //appSetting.Values.Remove("idNum"); try { var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.FindAllByResource(resourceName); foreach (var item in credentialList) { vault.Remove(item); } } catch { } appSetting.Values["CommunityPerInfo"] = false; appSetting.Values["isUseingBackgroundTask"] = false; IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder; IStorageFile storageFileWR = await applicationFolder.CreateFileAsync("kb", CreationCollisionOption.OpenIfExists); try { await storageFileWR.DeleteAsync(); if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList")) { if (JumpList.IsSupported()) DisableSystemJumpListAsync(); } } catch (Exception) { Debug.WriteLine("个人 -> 切换账号删除课表数据异常"); } Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(LoginPage)); }