private PasswordCredential prefs(string name, string key) { PasswordCredential credential = null; var vault = new PasswordVault(); return(vault.Retrieve(name, key)); }
private void ValidatePasswordCredential(PasswordCredential credential) { if (credential == null || string.IsNullOrEmpty(credential.KeyId) || string.IsNullOrEmpty(credential.Value) || credential.StartDate == null || credential.EndDate == null) { throw new InvalidOperationException(ProjectResources.PasswordCredentialNotValid); } }
public static void SetPassword(string password) { string username = GetUsername(); PasswordCredential cred = new PasswordCredential(PASSWORD, username, password); PasswordVault vault = new PasswordVault(); vault.Add(cred); }
private void SaveCredential(string userName, string password) { var vault = new PasswordVault(); var credential = new PasswordCredential(RESOURCE_NAME, userName, password); // Permanently stores credential in the password vault. vault.Add(credential); }
public void SaveCredentials(string resource, string username, string password) { // Create and store the user credentials. var credential = new PasswordCredential(resource, username, password); new PasswordVault().Add(credential); }
public Credential(PasswordCredential cred) { cred.RetrievePassword(); UserName = cred.UserName; Password = cred.Password; Resource = cred.Resource; }
// Define a method that performs the authentication process // using a Facebook sign-in. private async System.Threading.Tasks.Task <bool> AuthenticateAsync(MobileServiceAuthenticationProvider provider) { string message; bool success = false; // This sample uses the Facebook provider. // 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.ToString()).FirstOrDefault(); } catch (Exception) { // When there is no matching resource an error occurs, which we ignore. } if (false)//credential != null) { // Create a user from the stored credentials. user = new MobileServiceUser(credential.UserName); credential.RetrievePassword(); user.MobileServiceAuthenticationToken = credential.Password; // Set the user from the stored credentials. App.MobileService.CurrentUser = user; // Consider adding a check to determine if the token is // expired, as shown in this post: https://aka.ms/jww5vp. success = true; message = string.Format("Cached credentials for user - {0}", user.UserId); } else { try { // Sign in with the identity provider. user = await App.MobileService .LoginAsync(provider, "MobileAppTestForLulixue"); // Create and store the user credentials. credential = new PasswordCredential(provider.ToString(), user.UserId, user.MobileServiceAuthenticationToken); vault.Add(credential); success = true; message = string.Format("You are now signed in - {0}", user.UserId); } catch (MobileServiceInvalidOperationException) { message = "You must sign in. Sign-In Required"; } } var dialog = new MessageDialog(message); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); return(success); }
public string EncodeSecretKeysToBase64(PasswordCredential passwordCredential) { Arguments.NotNull(passwordCredential, nameof(passwordCredential)); passwordCredential.RetrievePassword(); var concatenatedSecretKeys = $"{passwordCredential.UserName} {passwordCredential.Password}"; return(concatenatedSecretKeys.EncodeToBase64()); }
private static Resources.SamlCredential Convert(PasswordCredential passwordCredential, UrlHelper urlHelper) { return(new Resources.SamlCredential { Id = urlHelper.GetWebId <Controllers.PasswordCredentialController>(passwordCredential.id), Actor = passwordCredential.actorId, UserId = passwordCredential.userId, }); }
public void ValueConverter_SerializesClass_AsStringProperty() { var passwordCredential = new PasswordCredential("thisIsAPassword"); var chClient = new CredHubClient(); var serialized = JsonSerializer.Serialize(passwordCredential, chClient.SerializerOptions); Assert.Equal("\"thisIsAPassword\"", serialized); }
public void TestPasswordCredential() { string json = @"{ ""username"" : ""test_user"", ""password"" : ""mypass"" }"; PasswordCredential credentials = JsonConvert.DeserializeObject <PasswordCredential>(json); Assert.IsNotNull(credentials); Assert.AreEqual("test_user", credentials.Username); Assert.AreEqual("mypass", credentials.Password); }
public void RemoveSecret(string name) { PasswordCredential credential = GetCredential(name); if (credential != null) { m_store.Remove(credential); } }
private void SaveCredential(string userName, string password) { var vault = new PasswordVault(); this.userName = userName; var credential = new PasswordCredential(RESOURCE_NAME, userName, password); vault.Add(credential); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { EndDate = StartDate.AddYears(1); if (this.IsParameterBound(c => c.ApplicationObject)) { ObjectId = ApplicationObject.ObjectId; } else if (this.IsParameterBound(c => c.ApplicationId)) { ObjectId = ActiveDirectoryClient.GetAppObjectIdFromApplicationId(ApplicationId); } else if (this.IsParameterBound(c => c.DisplayName)) { ObjectId = ActiveDirectoryClient.GetAppObjectIdFromDisplayName(DisplayName); } if (Password != null && Password.Length > 0) { string decodedPassword = SecureStringExtensions.ConvertToString(Password); // Create object for password credential var passwordCredential = new PasswordCredential() { EndDate = EndDate, StartDate = StartDate, KeyId = Guid.NewGuid().ToString(), Value = decodedPassword }; if (ShouldProcess(target: ObjectId.ToString(), action: string.Format("Adding a new password to application with objectId {0}", ObjectId))) { WriteObject(ActiveDirectoryClient.CreateAppPasswordCredential(ObjectId, passwordCredential)); } } else if (this.IsParameterBound(c => c.CertValue)) { // Create object for key credential var keyCredential = new KeyCredential() { EndDate = EndDate, StartDate = StartDate, KeyId = Guid.NewGuid().ToString(), Value = CertValue, Type = "AsymmetricX509Cert", Usage = "Verify" }; if (ShouldProcess(target: ObjectId.ToString(), action: string.Format("Adding a new certificate to application with objectId {0}", ObjectId))) { WriteObject(ActiveDirectoryClient.CreateAppKeyCredential(ObjectId, keyCredential)); } } else { throw new InvalidOperationException("No valid keyCredential or passowrdCredential to update!!"); } }); }
public void RemoveCredentials(string login) { PasswordCredential cred = _vault.Retrieve("gitme", login); _vault.Remove(cred); _roamingSettings.Values["login"] = ""; _appCredentials.Login = ""; _appCredentials.Password = ""; }
public static void StoreTokenInVault(TokenResponse response) { RemoveTokenFromVault(); var vault = new PasswordVault(); var pwdc = new PasswordCredential(TimesheetConstants.ClientId, TimesheetConstants.VaultUserName, response.Raw); vault.Add(pwdc); }
public static async Task <bool> AuthenticateAsync() { bool success = false; var provider = MobileServiceAuthenticationProvider.Google; // Use the PasswordVault to securely store and access credentials. var vault = new PasswordVault(); PasswordCredential credential = null; try { // Try to get an existing credential from the vault. credential = vault.FindAllByResource(provider.ToString()).FirstOrDefault(); } catch (Exception) { // When there is no matching resource an error occurs, which we ignore. } if (credential != null) { // Create a user from the stored credentials. var user = new MobileServiceUser(credential.UserName); credential.RetrievePassword(); user.MobileServiceAuthenticationToken = credential.Password; // Set the user from the stored credentials. App.MobileClient.CurrentUser = user; // Consider adding a check to determine if the token is // expired, as shown in this post: http://aka.ms/jww5vp. success = true; } else { try { // Login with the identity provider. var user = await App.MobileClient.LoginAsync(provider, "{app-name}"); // Create and store the user credentials. credential = new PasswordCredential(provider.ToString(), user.UserId, user.MobileServiceAuthenticationToken); vault.Add(credential); success = true; } catch (MobileServiceInvalidOperationException) { var dialog = new MessageDialog("You must log in. Login Required"); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } } return(success); }
private void SaveAndLogin(PasswordCredential cred, MUConnector connector) { App.MainViewModel.connector = connector; PasswordVault vault = new PasswordVault(); vault.Add(cred); App.MainViewModel.SignOnSaved = true; Frame.Navigate(typeof(FoodTile.Views.MainPage)); }
private async void ExecuteLoginCommand() { Message = string.Empty; bool successfulAuth = false; IsLoading = true; try { // Attempt to sign the user into SharePoint Online using Integrated Windows Auth or username + password successfulAuth = await SharePointAuthentication.Create( new Uri(ServerUrl), Username, Userpassword, false); } catch (Exception) { } IsLoading = false; if (!successfulAuth) { Message = "Anmeldung fehlgeschlagen!"; return; } if (SaveUserCredentials) { var pwVault = new PasswordVault(); IReadOnlyList <PasswordCredential> credentials = null; // Find existing credentials try { credentials = pwVault.FindAllByResource(PasswordVaultName); // Remove existing credentials if (credentials != null) { foreach (PasswordCredential credential in credentials) { pwVault.Remove(credential); } } } catch { } var pwCredentials = new PasswordCredential(PasswordVaultName, Username, Userpassword); pwCredentials.Properties.Add(new KeyValuePair <string, object>("Url", ServerUrl)); pwVault.Add(pwCredentials); } Messenger.Default.Send <bool>(true, "ClosePopUp"); }
public void PersistPincode(MobilePolicy policy) { DeletePincode(); var newPin = new PasswordCredential(PasswordVaultSecuredData, PasswordVaultPincode, JsonConvert.SerializeObject(policy)); _vault.Add(newPin); LoggingService.Log("pincode added to vault", LoggingLevel.Verbose); }
public static PSADCredential ToPSADCredential(this PasswordCredential credential) { return(new PSADCredential { KeyId = credential.KeyId, StartDate = credential.StartDate == null ? string.Empty : credential.StartDate.ToString(), EndDate = credential.EndDate == null ? string.Empty : credential.EndDate.ToString(), Type = "Password" }); }
public static void SaveUserCredentials(UserAuthenticationEntity userAuthenticationEntity) { var vault = new PasswordVault(); var credential = new PasswordCredential("key", "user", userAuthenticationEntity.ToString()); vault.Add(credential); }
public PSADCredential CreateSpPasswordCredential(string spObjectId, PasswordCredential credential) { ValidatePasswordCredential(credential); var passwordCredsList = GetSpPasswordCredentials(spObjectId); // Add new PasswordCredential to existing KeyCredential list passwordCredsList.Add(credential); PatchSpPasswordCredentials(spObjectId, passwordCredsList); return(credential.ToPSADCredential()); }
public UserCredential(PasswordCredential creden) { _credential = creden; _credential.RetrievePassword(); Tuple <String, String> value = AccountControl.ReverseStringsMerge(_credential.UserName); _name = value.Item2; _school = value.Item1; _password = _credential.Password; }
/// <summary> /// Clears any saved credentials in the Locker and sets the current user to null. /// </summary> public static void DeleteSavedUser() { CurrentUser = null; try { PasswordCredential credential = GetStoredCredential(); new PasswordVault().Remove(credential); } catch { } }
public string GetUserNameFromLocker() { PasswordCredential credential = GetCredentialFromLocker(); if (credential != null) { return(credential.UserName); } return(string.Empty); }
public void PersistPincode(MobilePolicy policy) { DeletePincode(); var newPin = new PasswordCredential(PasswordVaultSecuredData, PasswordVaultPincode, JsonConvert.SerializeObject(policy)); _vault.Add(newPin); PlatformAdapter.SendToCustomLogger("AuthStorageHelper.PersistPincode - pincode added to vault", LoggingLevel.Verbose); }
/// <summary> /// The save. /// </summary> /// <param name="key"> /// The key. /// </param> /// <param name="expiration"> /// The expiration for the token /// </param> /// <param name="token"> /// The token. /// </param> public void Save(string key, DateTime expiration, string token) { var vault = new PasswordVault(); var credential = new PasswordCredential( key, Username, string.Format("{0}|{1}", expiration, token)); vault.Add(credential); }
private static void AddCredentialToLocker() { if (!(string.IsNullOrWhiteSpace(_username) || string.IsNullOrWhiteSpace(_password) || string.IsNullOrWhiteSpace(_serverUrl))) { RemoveCredentials(); var credential = new PasswordCredential(_serverUrl, _username, _password); var vault = new Windows.Security.Credentials.PasswordVault(); vault.Add(credential); } }
private string StoreCredential(Identity.Client.AuthenticationResult authResult) { _user = authResult.User; _expiration = authResult.ExpiresOn; ApplicationData.Current.LocalSettings.Values[STORAGEKEYEXPIRATION] = authResult.ExpiresOn; ApplicationData.Current.LocalSettings.Values[STORAGEKEYUSER] = authResult.User.DisplayableId; _passwordCredential = new PasswordCredential(STORAGEKEYACCESSTOKEN, authResult.User.DisplayableId, authResult.Token); _vault.Add(_passwordCredential); return(authResult.Token); }