Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public async void InvalidateAlternativeLogin()
        {
            PasswordInfoModel model = await GetPasswordInfoModelAsync();

            if (model != null)
            {
                model.EncryptedPassword = null;
                await _storageService.SetCachedTextFileAsync(FileName, JsonConvert.SerializeObject(model));
            }
        }
Ejemplo n.º 3
0
        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));
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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);
        }