QUR/Authenticator/Pages/Index.razor

60 lines
1.5 KiB
Plaintext
Raw Normal View History

2023-08-23 00:54:11 +02:00
@page "/"
@using System.Text;
@inject NavigationManager navigator
<PageTitle>Code</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Here's your code</MudText>
@* <MudText Typo="Typo.subtitle1">IMPORTANT: Take only 17 charecters from anywhere in the code!</MudText>*@
<MudPaper Class="pa-4" >
<MudText Class="mb-8 flex-wrap" Typo="Typo.body1" Style="word-wrap:break-word;">@authCode</MudText>
</MudPaper>
@if (verified)
{
<MudText Typo="Typo.body2"> Verified!</MudText>
}
@code {
string authCode = "";
bool verified = false;
protected override async Task OnInitializedAsync()
{
string semiCode = GetCode();
string guess = semiCode.Skip(15).Take(17).ToString();
if (authCode.Contains(guess))
verified = true;
await Task.Delay(30000);
navigator.NavigateTo("", true);
}
public string GetCode()
{
var time = DateTime.Now;
Random random = new Random(time.Hour);
var sb = new StringBuilder();
for (int i = 0; i < 100; i++)
{
string salt = (i + random.NextDouble()).ToString();
sb.AppendLine(salt);
}
string semicode = Base64Encode(time.ToString("HH") + sb.ToString());
semicode = semicode.Trim('=');
authCode = semicode;
return semicode;
}
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
}