Esempio n. 1
0
        private async Task OnTestRiskPasswordValidSubmitAsync(EditContext editContext)
        {
            try
            {
                var passwordInRisk = await RiskPasswordService.GetRiskPasswordTestAsync(testRiskPasswordForm.Model.Password);

                testRiskPasswordForm.Model.IsValid = !passwordInRisk;
            }
            catch
            {
                testRiskPasswordForm.Model.IsValid = true;
                throw;
            }
        }
Esempio n. 2
0
 private async Task DefaultRiskPasswordLoadAsync()
 {
     riskPasswordLoadError = null;
     try
     {
         uploadRiskPassword = await RiskPasswordService.GetRiskPasswordInfoAsync();
     }
     catch (TokenUnavailableException)
     {
         await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
     }
     catch (Exception ex)
     {
         riskPasswordLoadError = ex.Message;
     }
 }
Esempio n. 3
0
        private async Task OnTestRiskPasswordValidSubmitAsync(EditContext editContext)
        {
            try
            {
                var passwordSha1Hash = testRiskPasswordForm.Model.Password.Sha1Hash();
                var riskPassword     = await RiskPasswordService.GetRiskPasswordAsync(passwordSha1Hash);

                if (riskPassword != null)
                {
                    testRiskPasswordForm.Model.IsValid = false;
                }
            }
            catch (FoxIDsApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    testRiskPasswordForm.Model.IsValid = true;
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 4
0
        public async Task OnUploadRiskPasswordValidSubmitAsync(EditContext editContext)
        {
            uploadRiskPassword.Form.ClearFieldError(nameof(uploadRiskPassword.Form.Model.File));

            foreach (var file in await fileReaderService.CreateReference(inputTypeFileElement).EnumerateFilesAsync())
            {
                var fileInfo = await file.ReadFileInfoAsync();

                if (fileInfo.Size > GeneralUploadRiskPasswordViewModel.RiskPasswordMaxFileSize)
                {
                    uploadRiskPassword.Form.SetFieldError(nameof(uploadRiskPassword.Form.Model.File), $"That's too big. Max size: {GeneralUploadRiskPasswordViewModel.RiskPasswordMaxFileSize} bytes.");
                    return;
                }

                uploadRiskPassword.UploadState = GeneralUploadRiskPasswordViewModel.UploadStates.Active;
                StateHasChanged();
                var    riskPasswords = new List <RiskPassword>();
                byte[] buffer        = new byte[131072];
                string text          = string.Empty;
                await using (var stream = await file.OpenReadAsync())
                {
                    while (uploadRiskPassword.UploadState == GeneralUploadRiskPasswordViewModel.UploadStates.Active)
                    {
                        if ((await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
                        {
                            text += Encoding.ASCII.GetString(buffer);
                            var lineSplit = text.Split(Environment.NewLine);
                            var lineCount = 0;
                            foreach (var line in lineSplit)
                            {
                                lineCount++;
                                if (lineCount < lineSplit.Length)
                                {
                                    var split         = line.Split(':');
                                    var passwordCount = Convert.ToInt32(split[1]);
                                    if (passwordCount >= GeneralUploadRiskPasswordViewModel.RiskPasswordMoreThenCount)
                                    {
                                        riskPasswords.Add(new RiskPassword {
                                            PasswordSha1Hash = split[0], Count = passwordCount
                                        });
                                        if (riskPasswords.Count >= GeneralUploadRiskPasswordViewModel.UploadRiskPasswordBlokCount)
                                        {
                                            uploadRiskPassword.Form.Model.UploadCount += GeneralUploadRiskPasswordViewModel.UploadRiskPasswordBlokCount;
                                            StateHasChanged();
                                            await RiskPasswordService.UpdateUserAsync(new RiskPasswordRequest { RiskPasswords = riskPasswords });

                                            riskPasswords = new List <RiskPassword>();
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    text = line;
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (uploadRiskPassword.UploadState == GeneralUploadRiskPasswordViewModel.UploadStates.Active && riskPasswords.Count > 0)
                    {
                        uploadRiskPassword.Form.Model.UploadCount += riskPasswords.Count;
                        StateHasChanged();
                        await RiskPasswordService.UpdateUserAsync(new RiskPasswordRequest { RiskPasswords = riskPasswords });
                    }
                }
            }
            uploadRiskPassword.UploadState = GeneralUploadRiskPasswordViewModel.UploadStates.Done;
            await DefaultRiskPasswordLoadAsync();
        }