MFACodeGenerator/MFACodeGenerator.MAUI/MainPage.xaml.cs

44 lines
1.2 KiB
C#

using OtpNet;
namespace MFACodeGenerator.MAUI
{
public partial class MainPage : ContentPage
{
int count = 0;
public MainPage()
{
InitializeComponent();
}
private async void OnGenerateMFACode(object s, EventArgs e)
{
try
{
var key = Base32Encoding.ToBytes(InputBox.Text.Replace(" ", string.Empty));
var secretCode =
new Totp(key, 30, OtpHashMode.Sha1, 6);
var authCode = secretCode.ComputeTotp();
MFACodeOutput.Text = authCode;
//Clipboard.SetText(authCode, TextDataFormat.Text);
await Clipboard.SetTextAsync(authCode);
}
catch
{
MFACodeOutput.Text = "Invalid TOTP Secret... Check your inputs!";
}
}
private void OnCounterClicked(object sender, EventArgs e)
{
count++;
if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";
SemanticScreenReader.Announce(CounterBtn.Text);
}
}
}