本文整理汇总了C#中Windows.Security.Credentials.PasswordVault.FindAllByUserName方法的典型用法代码示例。如果您正苦于以下问题:C# PasswordVault.FindAllByUserName方法的具体用法?C# PasswordVault.FindAllByUserName怎么用?C# PasswordVault.FindAllByUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Security.Credentials.PasswordVault
的用法示例。
在下文中一共展示了PasswordVault.FindAllByUserName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveSettings
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;
}
示例2: GetFifthplay
public Credential GetFifthplay()
{
if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("fifthplay-username"))
return new Credential();
var username = ApplicationData.Current.LocalSettings.Values["fifthplay-username"].ToString();
var vault = new PasswordVault();
var credentials = vault.FindAllByUserName(username)
.Single(f => f.Resource == "fifthplay");
credentials.RetrievePassword();
return new Credential
{
Username = username,
Password = credentials.Password
};
}
示例3: Read_Click
private void Read_Click(object sender, RoutedEventArgs e)
{
TextBox InputResourceValue = rootPage.FindName("InputResourceValue") as TextBox;
TextBox InputUserNameValue = rootPage.FindName("InputUserNameValue") as TextBox;
String result = "";
try
{
//
//Read a credential from PasswordVault by supplying resource or username
//
Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
IReadOnlyList<PasswordCredential> creds = null;
PasswordCredential cred = null;
//
//If both resource and username are empty, you can use RetrieveAll() to enumerate all credentials
//
if (InputUserNameValue.Text == "" && InputResourceValue.Text == "")
{
DebugPrint("Retrieving all credentials since resource or username are not specified.");
creds = vault.RetrieveAll();
}
//
//If there is only resouce, you can use FindAllByResource() to enumerate by resource.
//Note: the password will not be returned, you need to call retrieveAll with returned resouce and username to get the credential with password
//
else if (InputUserNameValue.Text == "")
{
DebugPrint("Retrieve credentials by resouces that you provided");
creds = vault.FindAllByResource(InputResourceValue.Text);
}
//
//If there is only username, you can use findbyusername() to enumerate by resource.
//Note: the password will not be returned, you need to call retrieveAll with returned resouce and username to get the credential with password
//
else if (InputResourceValue.Text == "")
{
DebugPrint("Retrieve credentials by username that you provided");
creds = vault.FindAllByUserName(InputUserNameValue.Text);
}
//
//Read by explicit resource and username name, result will be a single credential if it exists. Password will be returned.
//
else
cred = vault.Retrieve(InputResourceValue.Text, InputUserNameValue.Text);
//
//Output credential added to debug spew
//
if (creds != null)
{
DebugPrint("There are " + creds.Count + " credential(s) found.");
foreach (PasswordCredential c in creds)
{
try
{
PasswordCredential c1 = vault.Retrieve(c.Resource.ToString(), c.UserName.ToString());
result = "Credential read successfully. " + "Resource: " + c.Resource.ToString() + ", " + "Username: " + c.UserName.ToString() + "Password: " + c1.Password.ToString() + ".";
DebugPrint(result.ToString());
}
catch (Exception Error)
{
DebugPrint(Error.Message);
}
}
}
else if (cred != null)
{
result = "Credential read successfully. " + "Resource: " + cred.Resource + ", " + "Username: " + cred.UserName + "Password: " + cred.Password.ToString() + ".";
DebugPrint(result.ToString());
}
else
{
result = "Credential not found.";
DebugPrint(result.ToString());
}
}
catch (Exception Error) // No stored credentials, so none to delete
{
if (Error.HResult == -2147023728)
DebugPrint("Credential not found.");
else
DebugPrint(Error.Message);
}
}
示例4: PasswordVaultRetrieverMethod
private void PasswordVaultRetrieverMethod()
{
var vault = new PasswordVault();
try
{
var credentialList = vault.FindAllByUserName("TwitterAccessToken");
if (credentialList.Count <= 0) return;
var credentialList1 = vault.FindAllByUserName("TwitterAccessTokenSecret");
if (credentialList1.Count <= 0) return;
TwitterPlusIconVisibility = Visibility.Collapsed;
TwitterRemoveIconVisibility = Visibility.Visible;
}
catch (Exception ex)
{
TwitterPlusIconVisibility = Visibility.Visible;
TwitterRemoveIconVisibility = Visibility.Collapsed;
Debug.WriteLine(ex);
}
RaisePropertyChanged(() => TwitterPlusIconVisibility);
RaisePropertyChanged(() => TwitterRemoveIconVisibility);
}
示例5: PasswordVaultRemoverMethod
private async void PasswordVaultRemoverMethod(object obj)
{
switch (int.Parse(obj.ToString()))
{
case 1:
var vault = new PasswordVault();
try
{
var credentialList = vault.FindAllByUserName("TwitterAccessToken");
if (credentialList.Count <= 0) return;
var credential = vault.Retrieve("Friend", "TwitterAccessToken");
vault.Remove(new PasswordCredential("Friend", "TwitterAccessToken", credential.Password));
var credentialList1 = vault.FindAllByUserName("TwitterAccessTokenSecret");
if (credentialList1.Count <= 0) return;
var credential1 = vault.Retrieve("Friend", "TwitterAccessTokenSecret");
vault.Remove(new PasswordCredential("Friend", "TwitterAccessTokenSecret", credential1.Password));
TwitterPlusIconVisibility = Visibility.Visible;
TwitterRemoveIconVisibility = Visibility.Collapsed;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
break;
case 2:
var sess = FBSession.ActiveSession;
await sess.LogoutAsync();
FacebookPlusIconVisibility = Visibility.Visible;
FacebookRemoveIconVisibility = Visibility.Collapsed;
break;
default:
break;
}
RaisePropertyChanged(() => TwitterRemoveIconVisibility);
RaisePropertyChanged(() => TwitterPlusIconVisibility);
RaisePropertyChanged(()=>FacebookPlusIconVisibility);
RaisePropertyChanged(()=>FacebookRemoveIconVisibility);
}
示例6: TwitterPoster
private async Task TwitterPoster()
{
SosPageText += "\n Checking credentials... \n";
RaisePropertyChanged(() => SosPageText);
var vault = new PasswordVault();
try
{
var credentialList = vault.FindAllByUserName("TwitterAccessToken");
if (credentialList.Count <= 0)
{
SosPageText += "Twitter not configured \n";
return;
}
var twitteraccesstoken = vault.Retrieve("Friend", "TwitterAccessToken");
var twitteraccesstokensecret = vault.Retrieve("Friend", "TwitterAccessTokenSecret");
SosPageText += "Credentials Retrieved \n";
// Set up your credentials (https://apps.twitter.com)
//Use your own consumerKey and consumerSecret below!
await AuthTokens.KeyRetriever();
Auth.SetUserCredentials(AuthTokens.TwitterConsumerKey, AuthTokens.TwitterConsumerSecret,
twitteraccesstoken.Password, twitteraccesstokensecret.Password);
Tweet.PublishTweet(Message+" \n" + _latitude + "\n" + _longitude);
SosPageText += "Publishing Tweet... \n";
}
catch (Exception e)
{
SosPageText += "Twitter not configured \n";
Debug.WriteLine(e);
}
RaisePropertyChanged(()=>SosPageText);
}
示例7: TryGetPassword
public bool TryGetPassword(string username, out string password)
{
vault = new Windows.Security.Credentials.PasswordVault();
try
{
IReadOnlyList<PasswordCredential> creds = vault.FindAllByUserName(username);
foreach (var cred in creds)
{
if (cred.UserName == username )
{
cred.RetrievePassword();
password = cred.Password;
return true;
}
}
}
catch (Exception e)
{
}
password = null;
return false;
}
示例8: TwitterPoster
private static async void TwitterPoster()
{
Debug.WriteLine("Checking credentials... \n");
var vault = new PasswordVault();
try
{
var credentialList = vault.FindAllByUserName("TwitterAccessToken");
if (credentialList.Count <= 0)
{
Debug.WriteLine("Twitter not configured \n");
return;
}
var twitteraccesstoken = vault.Retrieve("Friend", "TwitterAccessToken");
var twitteraccesstokensecret = vault.Retrieve("Friend", "TwitterAccessTokenSecret");
Debug.WriteLine("Credentials Retrieved \n");
// Set up your credentials (https://apps.twitter.com)
//Use your own consumerKey and consumerSecret below!
await AuthTokens.KeyRetriever();
Auth.SetUserCredentials(AuthTokens.TwitterConsumerKey, AuthTokens.TwitterConsumerSecret,
twitteraccesstoken.Password, twitteraccesstokensecret.Password);
await LocationAccesser();
Tweet.PublishTweet(_message + " \n" + _latitude + "\n" + _longitude);
Debug.WriteLine("Publishing Tweet... \n");
}
catch (Exception e)
{
Debug.WriteLine("Twitter not configured \n");
Debug.WriteLine(e);
}
}
示例9: loadCredentials
Task<IPlayApi> loadCredentials()
{
var vault = new PasswordVault();
try {
var baseUrl = vault.FindAllByUserName("BaseUrl").First().Password;
var token = vault.FindAllByUserName("Token").First().Password;
return Observable.Return((IPlayApi)createPlayApiFromCreds(baseUrl, token)).ToTask();
} catch (Exception ex) {
return Observable.Throw<IPlayApi>(ex).ToTask();
}
}
示例10: RetrieveCredentials
private void RetrieveCredentials()
{
var resource = InputResourceValue.Text;
var userName = InputUserNameValue.Text;
// Clear previous output.
RetrievedCredentials.Items.Clear();
rootPage.NotifyUser("", NotifyType.StatusMessage);
var vault = new PasswordVault();
IReadOnlyList<PasswordCredential> creds = null;
// The credential retrieval functions raise an "Element not found"
// exception if there were no matches.
try
{
// Perform the desired queryuserName
if (resource == "" && userName == "")
{
// Both resource and user name are empty: Use retrieveAll().
creds = vault.RetrieveAll();
}
else if (userName == "")
{
// Resource is provided but no user name: Use findAllByResource().
creds = vault.FindAllByResource(resource);
}
else if (resource == "")
{
// User name is provided but no resource: Use findByUserName().
creds = vault.FindAllByUserName(userName);
}
else
{
// Both resource and user name are provided: Use retrieve().
PasswordCredential cred = vault.Retrieve(resource, userName);
// Add it to our results if the retrieval was successful.
if (cred != null)
{
creds = new List<PasswordCredential>() { cred };
}
}
}
catch (Exception e)
{
if (e.HResult != ElementNotFound)
{
throw;
}
}
// Display the results. Note that the password field is initially blank.
// You must call retrievePassword() to get the password.
if (creds == null || creds.Count == 0)
{
rootPage.NotifyUser("No matching credentials", NotifyType.ErrorMessage);
}
else
{
ItemCollection items = RetrievedCredentials.Items;
foreach (PasswordCredential cred in creds)
{
var item = new TextBlock();
item.DataContext = cred;
item.Text = cred.Resource + ": " + cred.UserName;
items.Add(item);
}
rootPage.NotifyUser("Credentials found: " + items.Count.ToString(), NotifyType.StatusMessage);
}
}