FindAllByUserName() 공개 메소드

public FindAllByUserName ( [ userName ) : IVectorView
userName [
리턴 IVectorView
예제 #1
0
        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
0
        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
0
        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: "******"Password: "******".";
                            DebugPrint(result.ToString());
                        }
                        catch (Exception Error)
                        {
                            DebugPrint(Error.Message);
                        }
                    }
                }

                else if (cred != null)
                {
                    result = "Credential read successfully. " + "Resource: " + cred.Resource + ", " + "Username: "******"Password: "******".";
                    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);
            }
            

        }
        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);

        }
        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);
        }
        private void Read_Click(object sender, RoutedEventArgs e)
        {
            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 == "")
                {
                    rootPage.NotifyUser("Retrieving all credentials since resource or username are not specified.", NotifyType.StatusMessage);
                    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 == "")
                {
                    rootPage.NotifyUser("Retrieve credentials by resouces that you provided", NotifyType.StatusMessage);
                    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 == "")
                {
                    rootPage.NotifyUser("Retrieve credentials by username that you provided", NotifyType.StatusMessage);
                    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)
                {
                    rootPage.NotifyUser("There are " + creds.Count + " credential(s) found.", NotifyType.StatusMessage);
                    foreach (PasswordCredential c in creds)
                    {
                        try
                        {
                            PasswordCredential c1 = vault.Retrieve(c.Resource.ToString(), c.UserName.ToString());
                            rootPage.NotifyUser("Credential read successfully. " + "Resource: " + c.Resource.ToString() + ", " + "Username: "******"Password: "******".", NotifyType.StatusMessage);
                        }
                        catch (Exception Error)
                        {
                            rootPage.NotifyUser(Error.Message, NotifyType.ErrorMessage);
                        }
                    }
                }

                else if (cred != null)
                {
                    rootPage.NotifyUser("Credential read successfully. " + "Resource: " + cred.Resource + ", " + "Username: "******"Password: "******".", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("Credential not found.", NotifyType.StatusMessage);
                }
            }
            catch (Exception Error)
            {
                if (Error.HResult == -2147023728)
                {
                    rootPage.NotifyUser("Credential not found.", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser(Error.Message, NotifyType.ErrorMessage);
                }
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
 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;
 }
예제 #9
0
        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);
            }

            
        }
예제 #10
0
        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();
            }
        }
        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);
            }
        }