本文整理汇总了C#中Windows.Security.Credentials.PasswordVault.Retrieve方法的典型用法代码示例。如果您正苦于以下问题:C# PasswordVault.Retrieve方法的具体用法?C# PasswordVault.Retrieve怎么用?C# PasswordVault.Retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Security.Credentials.PasswordVault
的用法示例。
在下文中一共展示了PasswordVault.Retrieve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyUserCredentials
public async Task<TunesUser> VerifyUserCredentials()
{
TunesUser tunesUser = null;
Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
try
{
await Task.Run(() =>
{
var userName = (string)Windows.Storage.ApplicationData.Current.RoamingSettings.Values["username"];
if (!string.IsNullOrEmpty(userName))
{
var passwordCredential = vault.Retrieve(PasswordVaultResourceName, userName);
if (passwordCredential != null)
{
tunesUser = this.User = new TunesUser
{
UserName = userName,
Password = vault.Retrieve(PasswordVaultResourceName, passwordCredential.UserName).Password
};
}
}
});
}
catch { }
return tunesUser;
}
示例2: Storage
public Storage(string fileName) {
this.fileName = new String(fileName.ToCharArray());
PasswordVault vault = new PasswordVault();
try {
this.password = vault.Retrieve(Conf.resource, Conf.username).Password;
}
catch (Exception e) {
vault.Add(new PasswordCredential(Conf.resource, Conf.username, CryptographicBuffer.EncodeToBase64String(CryptographicBuffer.GenerateRandom(64))));
this.password = vault.Retrieve(Conf.resource, Conf.username).Password;
}
}
示例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";
}
}
示例4: SecureLoadPassword
private dynamic SecureLoadPassword(string username)
{
// Credential Lockerから資格情報を取得する
PasswordVault vault = new PasswordVault();
PasswordCredential credential = vault.Retrieve(RESOURCE, username);
return new { UserName = credential.UserName, Password = credential.Password };
}
示例5: GetPassword
public static string GetPassword()
{
PasswordVault passwordVault = new PasswordVault();
if (!passwordVault.RetrieveAll().Any(credential => credential.UserName == UserNameText && credential.Resource == ResourceText))
{
SetPassword();
}
return passwordVault.Retrieve(ResourceText, UserNameText).Password;
}
示例6: 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);
}
示例7: RetrieveCredential
public static PasswordCredential RetrieveCredential(string username)
{
try
{
PasswordVault vault = new PasswordVault();
return vault.Retrieve(CredentialSource, username);
}
catch
{
return null;
}
}
示例8: Unprotect
public string Unprotect(string key)
{
try
{
var vault = new PasswordVault();
return vault.Retrieve(Package.Current.Id.Name, key).Password;
}
catch
{
return null;
}
}
示例9: Retrieve
public string Retrieve(string key)
{
try
{
var vault = new PasswordVault();
return vault.Retrieve(key, "username").Password;
}
catch
{
return null;
}
}
示例10: 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)
{
}
}
示例11: ClearCurrentUser
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"] = "";
}
示例12: TryAuthenticateSilently
public static async Task<bool> TryAuthenticateSilently(bool useCachedCredentials = true)
{
MobileServiceUser user = null;
var vault = new PasswordVault();
PasswordCredential savedCredentials = null;
if (useCachedCredentials && LegacyUserId.Value != null)
{
try
{
savedCredentials = vault.FindAllByResource(ProviderId).FirstOrDefault();
}
catch (Exception)
{
// No credentials found.
}
}
if (savedCredentials != null)
{
user = new MobileServiceUser(savedCredentials.UserName)
{
MobileServiceAuthenticationToken = vault.Retrieve(ProviderId, savedCredentials.UserName).Password
};
MobileService.Client.CurrentUser = user;
}
if (user == null)
{
try
{
user = await DoLoginAsync(CredentialPromptType.DoNotPrompt);
}
catch (Exception)
{
// Do nothing
}
if (user != null)
{
vault.Add(new PasswordCredential(ProviderId, user.UserId, user.MobileServiceAuthenticationToken));
}
}
return user != null;
}
示例13: LoadToken
public void LoadToken()
{
if (this.IsFirst) { return; }
try
{
var p = new PasswordVault();
var accessToken = p.Retrieve("TwitterAppSample.AccessToken", this.ScreenName);
var accessTokenSecret = p.Retrieve("TwitterAppSample.AccessTokenSecret", this.ScreenName);
this.tokens = Tokens.Create(
Constants.ConsumerKey,
Constants.ConsumerSecret,
accessToken.Password,
accessTokenSecret.Password);
this.tokens.Followers.ListAsync();
this.OnPropertyChanged(() => this.IsAuth);
}
catch
{
// ignore
}
}
示例14: GetSavedCredentials
public PasswordCredential GetSavedCredentials(string resource) {
try {
var vault = new PasswordVault();
var credentials = vault.FindAllByResource(resource);
var cred = credentials.FirstOrDefault();
if (cred != null)
return vault.Retrieve(resource, cred.UserName);
else
return null;
}
// The password vault throws System.Exception if no credentials have been stored with this resource.
catch (Exception) {
return null;
}
}
示例15: GetCredentialsFromVault
private PasswordCredential GetCredentialsFromVault(PasswordVault vault)
{
PasswordCredential credentials;
try
{
credentials = vault.FindAllByResource(PasswordVaultResourceName).FirstOrDefault();
credentials = vault.Retrieve(PasswordVaultResourceName, credentials.UserName);
}
catch (Exception exception)
{
credentials = null;
this.Log(exception);
}
return credentials;
}