Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

1.7 KB
Raw Blame
@page "/account/manage/reset-authenticator"

@using Microsoft.AspNetCore.Identity

@inject UserManager<AdminUser> UserManager
@inject ILogger<ResetAuthenticator> Logger

<LayoutPageTitle>Reset authenticator key</LayoutPageTitle>

<h3 class="text-xl font-bold mb-4 dark:text-white">Reset authenticator key</h3>
<div class="bg-primary-100 border-l-4 border-primary-500 text-primary-700 p-4 mb-4" role="alert">
    <p class="mb-2">
        <UiIcon Icon="UiIcons.Exclamation" class="inline w-5 h-5 mr-2" />
        <strong>If you reset your authenticator key your authenticator app will not work until you reconfigure it.</strong>
    </p>
    <p>
        This process disables 2FA until you verify your authenticator app.
        If you do not complete your authenticator app configuration you may lose access to your account.
    </p>
</div>
<div>
    <form @formname="reset-authenticator" @onsubmit="OnSubmitAsync" method="post">
        <AntiforgeryToken/>
        <SubmitButton>Reset authenticator key</SubmitButton>
    </form>
</div>

@code {
    private async Task OnSubmitAsync()
    {
        var user = await UserManager.FindByIdAsync(UserService.User().Id);
        if (user == null)
        {
            throw new InvalidOperationException("User not found.");
        }

        await UserManager.SetTwoFactorEnabledAsync(user, false);
        await UserManager.ResetAuthenticatorKeyAsync(user);
        Logger.LogInformation("User with ID '{UserId}' has reset their authentication app key.", UserService.User().Id);

        GlobalNotificationService.AddSuccessMessage("Your authenticator app key has been reset, you will need to re-configure your authenticator app using the new key.");

        NavigationService.RedirectTo("account/manage/2fa");
    }

}