Skip to content

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

Add admin option to disable 2FA for user (#70)

Leendert de Borst8ba039ff2504
diff --git a/src/AliasVault.Admin/Main/Components/Layout/StatusPill.razor b/src/AliasVault.Admin/Main/Components/Layout/StatusPill.razor
new file mode 100644
index 000000000..9e3d5e25d
--- /dev/null
+++ b/src/AliasVault.Admin/Main/Components/Layout/StatusPill.razor
@@ -0,0 +1,19 @@
+@inherits ComponentBase
+
+<span class="@PillClass px-2 py-1 text-xs font-medium rounded-full">
+ @StatusText
+</span>
+
+@code {
+ /// <summary>
+ /// Set to true to show the pill as enabled.
+ /// </summary>
+ [Parameter]
+ public bool Enabled { get; set; }
+
+ private string PillClass => Enabled
+ ? "bg-green-100 text-green-800"
+ : "bg-red-100 text-red-800";
+
+ private string StatusText => Enabled ? "Enabled" : "Disabled";
+}
diff --git a/src/AliasVault.Admin/Main/Models/UserViewModel.cs b/src/AliasVault.Admin/Main/Models/UserViewModel.cs
index 977b1d605..79afc9817 100644
--- a/src/AliasVault.Admin/Main/Models/UserViewModel.cs
+++ b/src/AliasVault.Admin/Main/Models/UserViewModel.cs
@@ -27,6 +27,11 @@ public class UserViewModel
/// </summary>
public string UserName { get; set; } = string.Empty;
+ /// <summary>
+ /// Gets or sets a value indicating whether the user has two-factor authentication enabled.
+ /// </summary>
+ public bool TwoFactorEnabled { get; set; }
+
/// <summary>
/// Gets or sets the vault count.
/// </summary>
diff --git a/src/AliasVault.Admin/Main/Pages/Users/Users.razor b/src/AliasVault.Admin/Main/Pages/Users/Users.razor
index 642ab8a51..4ac8a60a9 100644
--- a/src/AliasVault.Admin/Main/Pages/Users/Users.razor
+++ b/src/AliasVault.Admin/Main/Pages/Users/Users.razor
@@ -35,6 +35,7 @@ else
<th scope="col" class="px-4 py-3"># Vaults</th>
<th scope="col" class="px-4 py-3"># Email claims</th>
<th scope="col" class="px-4 py-3">Storage</th>
+ <th scope="col" class="px-4 py-3">2FA</th>
<th scope="col" class="px-4 py-3">Last vault update</th>
<th scope="col" class="px-4 py-3">Actions</th>
</tr>
@@ -49,6 +50,7 @@ else
<td class="px-4 py-3">@user.VaultCount</td>
<td class="px-4 py-3">@user.EmailClaimCount</td>
<td class="px-4 py-3">@Math.Round((double)user.VaultStorageInKb / 1024, 1) MB</td>
+ <td class="px-4 py-3"><StatusPill Enabled="user.TwoFactorEnabled" /></td>
<td class="px-4 py-3">@user.LastVaultUpdate.ToString("yyyy-MM-dd HH:mm")</td>
<td class="px-4 py-3">
<a href="users/@user.Id" class="px-4 py-2 text-white bg-primary-600 rounded-lg hover:bg-primary-700 focus:ring-4 focus:ring-blue-300 dark:bg-primary-500 dark:hover:bg-primary-600 dark:focus:ring-primary-800">View</a>
@@ -119,6 +121,7 @@ else
u.Id,
u.UserName,
u.CreatedAt,
+ u.TwoFactorEnabled,
Vaults = u.Vaults.Select(v => new
{
v.FileSize,
@@ -135,6 +138,7 @@ else
{
Id = user.Id,
UserName = user.UserName?.ToLower() ?? "N/A",
+ TwoFactorEnabled = user.TwoFactorEnabled,
CreatedAt = user.CreatedAt,
VaultCount = user.Vaults.Count(),
EmailClaimCount = user.EmailClaims.Count(),
diff --git a/src/AliasVault.Admin/Main/Pages/Users/View.razor b/src/AliasVault.Admin/Main/Pages/Users/View.razor
index c7174ea61..53de71aa6 100644
--- a/src/AliasVault.Admin/Main/Pages/Users/View.razor
+++ b/src/AliasVault.Admin/Main/Pages/Users/View.razor
@@ -32,6 +32,26 @@ else
<label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Id</label>
<div>@User.Id</div>
</div>
+ <div class="flex items-center space-x-2">
+ <span class="text-sm font-medium text-gray-900 dark:text-white">2FA Status:</span>
+ <StatusPill Enabled="@User.TwoFactorEnabled" />
+ <span>Authenticator key(s) active: @TwoFactorKeysCount</span>
+ @if (User.TwoFactorEnabled)
+ {
+ <button @onclick="DisableTwoFactor" class="px-3 py-2 text-xs font-medium text-center text-white bg-red-700 rounded-lg hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-800">
+ Disable 2FA
+ </button>
+ }
+ else
+ {
+ if (TwoFactorKeysCount > 0)
+ {
+ <button @onclick="EnableTwoFactor" class="px-3 py-2 text-xs font-medium text-center text-white bg-red-700 rounded-lg hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-800">
+ Enable 2FA
+ </button>
+ }
+ }
+ </div>
</div>
</div>
</div>
@@ -106,6 +126,7 @@ else
private bool IsLoading { get; set; } = true;
private AliasVaultUser? User { get; set; } = new();
+ private int TwoFactorKeysCount { get; set; }
private List<Vault> VaultList { get; set; } = new();
private List<UserEmailClaim> EmailClaimList { get; set; } = new();
@@ -136,6 +157,9 @@ else
// Load the aliases from the webapi via AliasService.
User = await DbContext.AliasVaultUsers.FindAsync(Id);
+ // Get count of user authenticator tokens.
+ TwoFactorKeysCount = await DbContext.UserTokens.CountAsync(x => x.UserId == User!.Id && x.Name == "AuthenticatorKey");
+
if (User is null)
{
// Error loading user.
@@ -163,4 +187,28 @@ else
IsLoading = false;
StateHasChanged();
}
+
+ private async Task DisableTwoFactor()
+ {
+ User = await DbContext.AliasVaultUsers.FindAsync(Id);
+
+ if (User != null)
+ {
+ User.TwoFactorEnabled = false;
+ await DbContext.SaveChangesAsync();
+ await LoadEntryAsync();
+ }
+ }
+
+ private async Task EnableTwoFactor()
+ {
+ User = await DbContext.AliasVaultUsers.FindAsync(Id);
+
+ if (User != null)
+ {
+ User.TwoFactorEnabled = true;
+ await DbContext.SaveChangesAsync();
+ await LoadEntryAsync();
+ }
+ }
}
diff --git a/src/AliasVault.Admin/wwwroot/css/tailwind.css b/src/AliasVault.Admin/wwwroot/css/tailwind.css
index 908302721..c1dbf40cb 100644
--- a/src/AliasVault.Admin/wwwroot/css/tailwind.css
+++ b/src/AliasVault.Admin/wwwroot/css/tailwind.css
@@ -1160,6 +1160,11 @@ video {
background-color: rgb(17 24 39 / var(--tw-bg-opacity));
}
+.bg-green-100 {
+ --tw-bg-opacity: 1;
+ background-color: rgb(220 252 231 / var(--tw-bg-opacity));
+}
+
.bg-green-50 {
--tw-bg-opacity: 1;
background-color: rgb(240 253 244 / var(--tw-bg-opacity));
@@ -1230,6 +1235,11 @@ video {
background-color: rgb(234 179 8 / var(--tw-bg-opacity));
}
+.bg-red-700 {
+ --tw-bg-opacity: 1;
+ background-color: rgb(185 28 28 / var(--tw-bg-opacity));
+}
+
.bg-opacity-50 {
--tw-bg-opacity: 0.5;
}
@@ -1760,6 +1770,11 @@ video {
background-color: rgb(113 63 18 / var(--tw-bg-opacity));
}
+.dark\:bg-red-600:is(.dark *) {
+ --tw-bg-opacity: 1;
+ background-color: rgb(220 38 38 / var(--tw-bg-opacity));
+}
+
.dark\:bg-opacity-80:is(.dark *) {
--tw-bg-opacity: 0.8;
}
@@ -1878,6 +1893,11 @@ video {
background-color: rgb(220 38 38 / var(--tw-bg-opacity));
}
+.dark\:hover\:bg-red-700:hover:is(.dark *) {
+ --tw-bg-opacity: 1;
+ background-color: rgb(185 28 28 / var(--tw-bg-opacity));
+}
+
.dark\:hover\:text-primary-500:hover:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(244 149 65 / var(--tw-text-opacity));