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


C# Credentials.PasswordVault类代码示例

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


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

示例1: Get

 public VaultCredential Get(string domain)
 {
     var vault = new PasswordVault();
     var credential = vault.FindAllByResource(domain).FirstOrDefault();
     credential.RetrievePassword();
     return new VaultCredential(credential.Resource, credential.UserName, credential.Password);
 }
开发者ID:Mordonus,项目名称:MALClient,代码行数:7,代码来源:PasswordVaultProvider.cs

示例2: 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;
 }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:26,代码来源:AccountService.cs

示例3: GetSecretFor

        public string GetSecretFor(string name)
        {
            var vault = new PasswordVault();
            try
            {
                if (vault.RetrieveAll().Count == 0)
                {
                    return "";
                }

                var credentialList = vault.FindAllByResource(_key);

                return credentialList
                    .Where(x => x.UserName == name)
                    .Select(x =>
                    {
                        x.RetrievePassword();
                        return x.Password;
                    })
                    .FirstOrDefault();
            }
            catch (Exception)
            {
                // Exception is thrown if the vault isn't properly initialised
                return "";
            }
        }
开发者ID:alexhardwicke,项目名称:Auth,代码行数:27,代码来源:PasswordHelper.cs

示例4: Save_Click

        private void Save_Click(object sender, RoutedEventArgs e)
        {
            String result = "";
            if (InputResourceValue.Text == "" || InputUserNameValue.Text == "" || InputPasswordValue.Password == "")
            {
                rootPage.NotifyUser("Inputs are missing. Resource, User name and Password are required", NotifyType.ErrorMessage);
            }
            else
            {
                try
                {
                    //Add a credential to PasswordVault by supplying resource, username, and password
                    PasswordVault vault = new PasswordVault();
                    PasswordCredential cred = new PasswordCredential(InputResourceValue.Text, InputUserNameValue.Text, InputPasswordValue.Password);
                    vault.Add(cred);

                    //Output credential added to debug spew
                    rootPage.NotifyUser("Credential saved successfully. " + "Resource: " + cred.Resource.ToString() + " Username: " + cred.UserName.ToString() + " Password: " + cred.Password.ToString() + ".", NotifyType.StatusMessage);
                }
                catch (Exception Error) // No stored credentials, so none to delete
                {
                    rootPage.NotifyUser(Error.Message, NotifyType.ErrorMessage);
                }
            }

        }
开发者ID:t-angma,项目名称:Windows-universal-samples,代码行数:26,代码来源:scenario1_addreadremovecredentials.xaml.cs

示例5: 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

示例6: ButtonBase_OnClick

        //Use your consumerKey and ConsumerSecret


        private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(pinText.Text))
            {
                var msgDialog = new MessageDialog("Please Enter the pin showed below");
                await msgDialog.ShowAsync();
            }
            else
            {
                var pinCode = pinText.Text.Trim();
                var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pinCode, authenticationContext);
                Auth.SetCredentials(userCredentials);

                var vault = new PasswordVault();
                vault.Add(new PasswordCredential("Friend", "TwitterAccessToken", userCredentials.AccessToken));
                vault.Add(new PasswordCredential("Friend", "TwitterAccessTokenSecret", userCredentials.AccessTokenSecret));
                var localSettings = ApplicationData.Current.LocalSettings;
                var frame = Window.Current.Content as Frame;

                if (localSettings.Values.ContainsKey("FirstTimeRunComplete"))
                {
                    frame?.Navigate(typeof(MainPage));
                }
                else
                {
                    frame?.Navigate(typeof(FirstTimeTutorial));
                }
            }
        }
开发者ID:prajjwaldimri,项目名称:Friend-App,代码行数:32,代码来源:TwitterAuthenticator.xaml.cs

示例7: CheckPreviousAuthentication

		public void CheckPreviousAuthentication()
		{
			PasswordCredential credential = null;

			var settings = ApplicationData.Current.RoamingSettings;

			var lastUsedProvider = settings.Values[LastUsedProvider] as string;
			if (lastUsedProvider != null)
			{
				try
				{
					var passwordVault = new PasswordVault();

					// Try to get an existing credential from the vault.
					credential = passwordVault.FindAllByResource(lastUsedProvider).FirstOrDefault();
				}
				catch (Exception)
				{
					// When there is no matching resource an error occurs, which we ignore.
				}
			}

			if (credential != null)
			{
				this.MobileService.User = new MobileServiceUser(credential.UserName);
				credential.RetrievePassword();
				this.MobileService.User.MobileServiceAuthenticationToken = credential.Password;

				this.OnNavigate?.Invoke(Tasks, null);
			}
		}
开发者ID:brentedwards,项目名称:MobileTasks,代码行数:31,代码来源:LoginViewModel.cs

示例8: Save

		public void Save(string userName, string password)
		{
			Clear();

			PasswordVault vault = new PasswordVault();
			vault.Add(new PasswordCredential(AppResourceName, userName, password));
		}
开发者ID:valeronm,项目名称:handyNews,代码行数:7,代码来源:CredentialService.cs

示例9: 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

示例10: login

        public async Task<bool> login()
        {
            Frame rootFrame = Window.Current.Content as Frame;

            PasswordVault vault = new PasswordVault();
            PasswordCredential cred = null;
            try
            {
                if (vault.FindAllByResource("email").ToString() != null)
                {
                    cred = vault.FindAllByResource("email")[0];
                    cred.RetrievePassword();
                    return await this.LoginWithEmail(cred.UserName.ToString(), cred.Password.ToString());
                }
            }
            catch (Exception)
            { }
            try
            {
                if (vault.FindAllByResource("facebook").ToString() != null)
                {
                    cred = vault.FindAllByResource("facebook")[0];
                    cred.RetrievePassword();
                    return await LoginWithFacebook();
                }
            }
            catch (Exception)
            {
                return false;
            }
            return false;

        }
开发者ID:newnottakenname,项目名称:FollowshowsWP,代码行数:33,代码来源:API.cs

示例11: LoadSettings

        public async static void LoadSettings()
        {
            //PasswordCredential cred = new PasswordCredential("redditMetro", Settings["UserName"].ToString(), Settings["Password"].ToString());
            try
            {
                PasswordVault = new PasswordVault();
            }
            catch (Exception)
            {
                // wtf is going on here!
            }

            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            var container = localSettings.CreateContainer(CONTAINER_NAME, ApplicationDataCreateDisposition.Always);
            Settings = container.Values;
            if (!Settings.ContainsKey("UserName"))
                Settings.Add("UserName", "");
            if (!Settings.ContainsKey("SavePassword"))
                Settings.Add("SavePassword", false);

            if (!String.IsNullOrEmpty(Settings["UserName"].ToString()) && (bool)Settings["SavePassword"])
            {
                LoginReddit();
            }
            else
            {
                isLoggedIn = false;
            }
        }
开发者ID:TacticalGoat,项目名称:reddit-Metro,代码行数:29,代码来源:App.xaml.cs

示例12: SaveCredential

        public static void SaveCredential(string userName, string password)
        {
            PasswordVault passwordVault = new PasswordVault();
            PasswordCredential passwordCredential = new PasswordCredential(RESOURCE, userName, password);

            passwordVault.Add(passwordCredential);
        }
开发者ID:RobertEichenseer,项目名称:RobEichMobileService,代码行数:7,代码来源:LogonCacher.cs

示例13: 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

示例14: SecureSavePassword

 private void SecureSavePassword(string username, string password)
 {
     // 資格情報をCredential Lockerへ保存します
     var vault = new PasswordVault();
     var credential = new PasswordCredential(RESOURCE, username, password);
     vault.Add(credential);
 }
开发者ID:runceel,项目名称:winstoreapprecipe,代码行数:7,代码来源:MainPage.xaml.cs

示例15: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            PasswordVault vault = new PasswordVault();

            try
            {
                var credentials = vault.FindAllByResource("creds");
                if (credentials.Any())
                {
                    var credential = credentials.First();
                    Username.Text = credential.UserName;
                    credential.RetrievePassword();
                    Password.Password = credential.Password;
                    Login(null, null);
                }
            }
            catch
            {
                // no credentials present, just ignore
            }

            if (e.Parameter != null)
            {
                Username.Text = e.Parameter.ToString();
            }
        }
开发者ID:frederikdesmedt,项目名称:Windows-App,代码行数:27,代码来源:LoginPage.xaml.cs


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