public async Task <string> TryAlternativeLogin() { try { PasswordInfoModel model = await GetPasswordInfoModelAsync(); if (model != null) { var key = await GetSignedKeyAsync(model.KeyPhrase); if (key != null) { if (model.EncryptedPassword != null) { var myPassword = _encryptionService.DecryptRaw(model.EncryptedPassword, key); return(myPassword); } } } } catch (Exception e) { LogHelper.Instance.LogException(e); } return(null); }
public async void InvalidateAlternativeLogin() { PasswordInfoModel model = await GetPasswordInfoModelAsync(); if (model != null) { model.EncryptedPassword = null; await _storageService.SetCachedTextFileAsync(FileName, JsonConvert.SerializeObject(model)); } }
public async void RegisterValidPassword(string hashedPassword) { PasswordInfoModel model = await GetPasswordInfoModelAsync(); if (model != null) { if (model.EncryptedPassword == null) { var key = await GetSignedKeyAsync(model.KeyPhrase); if (key != null) { model.EncryptedPassword = _encryptionService.EncryptRaw(hashedPassword, key); await _storageService.SetCachedTextFileAsync(FileName, JsonConvert.SerializeObject(model)); } } } }
private async Task <PasswordInfoModel> GetPasswordInfoModelAsync() { PasswordInfoModel model = null; var pwInfoFile = await _storageService.GetCachedTextFileAsync(FileName); if (pwInfoFile != null) { model = JsonConvert.DeserializeObject <PasswordInfoModel>(pwInfoFile); } if (model == null) { if (!await KeyCredentialManager.IsSupportedAsync()) { return(null); } model = new PasswordInfoModel { KeyPhrase = "sign this keyphrase of this bookmarked application to get a secure string" }; var keyCreationResult = await KeyCredentialManager.RequestCreateAsync(AccountId, KeyCredentialCreationOption.ReplaceExisting); if (keyCreationResult.Status == KeyCredentialStatus.Success) { model.PreferPassword = false; } else if (keyCreationResult.Status == KeyCredentialStatus.UserPrefersPassword) { model.PreferPassword = true; } await _storageService.SetCachedTextFileAsync(FileName, JsonConvert.SerializeObject(model)); } return(model); }