Skip to content

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

Add generic CSV importer based on an example template (#951)

Leendert de Borstf285b36c6160
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceGenericCsv.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceGenericCsv.razor
new file mode 100644
index 000000000..6df69c989
--- /dev/null
+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceGenericCsv.razor
@@ -0,0 +1,60 @@
+@using AliasVault.ImportExport.Models
+@using AliasVault.ImportExport.Importers
+@inject NavigationManager NavigationManager
+@inject GlobalNotificationService GlobalNotificationService
+@inject ILogger<ImportServiceGenericCsv> Logger
+@inject JsInteropService JsInteropService
+
+<ImportServiceCard
+ ServiceName="Generic CSV"
+ Description="Import credentials using a template CSV format"
+ LogoUrl="img/importers/generic-csv.svg"
+ ProcessFileCallback="ProcessFile">
+ <p class="text-gray-700 dark:text-gray-300 mb-4">Is the password manager you are using not supported? You can always import your credentials into AliasVault using a generic CSV template format instead.</p>
+ <ol class="text-sm text-gray-700 dark:text-gray-300 space-y-2 mb-4">
+ <li class="flex items-start space-x-2">
+ <span class="flex-shrink-0 w-5 h-5 bg-amber-400 text-white text-xs rounded-full flex items-center justify-center">1</span>
+ <span>Download the <button @onclick="DownloadTemplate" class="text-amber-600 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-200 underline">AliasVault Import CSV template</button></span>
+ </li>
+ <li class="flex items-start space-x-2">
+ <span class="flex-shrink-0 w-5 h-5 bg-amber-400 text-white text-xs rounded-full flex items-center justify-center">2</span>
+ <span>Open it in a spreadsheet program (Microsoft Excel, Google Sheets, etc.)</span>
+ </li>
+ <li class="flex items-start space-x-2">
+ <span class="flex-shrink-0 w-5 h-5 bg-amber-400 text-white text-xs rounded-full flex items-center justify-center">3</span>
+ <span>Fill in your credentials (replace the example data)</span>
+ </li>
+ <li class="flex items-start space-x-2">
+ <span class="flex-shrink-0 w-5 h-5 bg-amber-400 text-white text-xs rounded-full flex items-center justify-center">4</span>
+ <span>Save as CSV format and upload it below</span>
+ </li>
+ </ol>
+</ImportServiceCard>
+
+@code {
+ private static async Task<List<ImportedCredential>> ProcessFile(string fileContents)
+ {
+ return await GenericCsvImporter.ImportFromCsvAsync(fileContents);
+ }
+
+ private async Task DownloadTemplate()
+ {
+ try
+ {
+ var csvBytes = GenericCsvImporter.GetCsvTemplateBytes();
+ var fileName = $"aliasvault-import-template.csv";
+
+ // Create a memory stream from the byte array
+ using (MemoryStream memoryStream = new MemoryStream(csvBytes))
+ {
+ // Invoke JavaScript to initiate the download
+ await JsInteropService.DownloadFileFromStream(fileName, memoryStream.ToArray());
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Error downloading CSV template");
+ GlobalNotificationService.AddErrorMessage("Failed to download CSV template. Please try again.", true);
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor
index 8bcea12c7..535de0c7c 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor
@@ -32,6 +32,7 @@
<ImportServiceProtonPass />
<ImportServiceStrongbox />
<ImportServiceAliasVault />
+ <ImportServiceGenericCsv />
</div>
</div>
diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
index 9f0e54cf1..05ad89167 100644
--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
@@ -1460,6 +1460,11 @@ video {
background-color: rgb(254 243 199 / var(--tw-bg-opacity));
}
+.bg-amber-400 {
+ --tw-bg-opacity: 1;
+ background-color: rgb(251 191 36 / var(--tw-bg-opacity));
+}
+
.bg-amber-50 {
--tw-bg-opacity: 1;
background-color: rgb(255 251 235 / var(--tw-bg-opacity));
@@ -1920,6 +1925,11 @@ video {
letter-spacing: 0.05em;
}
+.text-amber-600 {
+ --tw-text-opacity: 1;
+ color: rgb(217 119 6 / var(--tw-text-opacity));
+}
+
.text-amber-700 {
--tw-text-opacity: 1;
color: rgb(180 83 9 / var(--tw-text-opacity));
@@ -2050,6 +2060,10 @@ video {
color: rgb(133 77 14 / var(--tw-text-opacity));
}
+.underline {
+ text-decoration-line: underline;
+}
+
.opacity-0 {
opacity: 0;
}
@@ -2299,6 +2313,11 @@ video {
--tw-gradient-to: #b8702f var(--tw-gradient-to-position);
}
+.hover\:text-amber-800:hover {
+ --tw-text-opacity: 1;
+ color: rgb(146 64 14 / var(--tw-text-opacity));
+}
+
.hover\:text-blue-700:hover {
--tw-text-opacity: 1;
color: rgb(29 78 216 / var(--tw-text-opacity));
@@ -2674,6 +2693,11 @@ video {
color: rgb(252 211 77 / var(--tw-text-opacity));
}
+.dark\:text-amber-400:is(.dark *) {
+ --tw-text-opacity: 1;
+ color: rgb(251 191 36 / var(--tw-text-opacity));
+}
+
.dark\:text-blue-300:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(147 197 253 / var(--tw-text-opacity));
@@ -2852,6 +2876,11 @@ video {
--tw-gradient-to: #d68338 var(--tw-gradient-to-position);
}
+.dark\:hover\:text-amber-200:hover:is(.dark *) {
+ --tw-text-opacity: 1;
+ color: rgb(253 230 138 / var(--tw-text-opacity));
+}
+
.dark\:hover\:text-blue-200:hover:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(191 219 254 / var(--tw-text-opacity));
diff --git a/apps/server/AliasVault.Client/wwwroot/img/importers/generic-csv.svg b/apps/server/AliasVault.Client/wwwroot/img/importers/generic-csv.svg
new file mode 100644
index 000000000..1fa9e473c
--- /dev/null
+++ b/apps/server/AliasVault.Client/wwwroot/img/importers/generic-csv.svg
@@ -0,0 +1,43 @@
+<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none">
+ <defs>
+ <linearGradient id="csv-gradient" x1="0%" y1="0%" x2="100%" y2="100%">
+ <stop offset="0%" style="stop-color:#10b981;stop-opacity:1" />
+ <stop offset="100%" style="stop-color:#059669;stop-opacity:1" />
+ </linearGradient>
+ </defs>
+
+ <!-- Background -->
+ <rect x="4" y="2" width="16" height="20" rx="2" ry="2" fill="url(#csv-gradient)" stroke="#047857" stroke-width="0.5"/>
+
+ <!-- File fold -->
+ <path d="M16 2v4h4" fill="none" stroke="#047857" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
+
+ <!-- CSV text -->
+ <text x="12" y="10" text-anchor="middle" fill="white" font-family="Arial, sans-serif" font-size="3" font-weight="bold">CSV</text>
+
+ <!-- Table grid -->
+ <g stroke="white" stroke-width="0.8" fill="none">
+ <!-- Horizontal lines -->
+ <line x1="6" y1="13" x2="18" y2="13"/>
+ <line x1="6" y1="15.5" x2="18" y2="15.5"/>
+ <line x1="6" y1="18" x2="18" y2="18"/>
+
+ <!-- Vertical lines -->
+ <line x1="9" y1="13" x2="9" y2="20"/>
+ <line x1="12" y1="13" x2="12" y2="20"/>
+ <line x1="15" y1="13" x2="15" y2="20"/>
+ </g>
+
+ <!-- Small dots to represent data -->
+ <g fill="white">
+ <circle cx="7.5" cy="14.25" r="0.3"/>
+ <circle cx="10.5" cy="14.25" r="0.3"/>
+ <circle cx="13.5" cy="14.25" r="0.3"/>
+ <circle cx="16.5" cy="14.25" r="0.3"/>
+
+ <circle cx="7.5" cy="16.75" r="0.3"/>
+ <circle cx="10.5" cy="16.75" r="0.3"/>
+ <circle cx="13.5" cy="16.75" r="0.3"/>
+ <circle cx="16.5" cy="16.75" r="0.3"/>
+ </g>
+</svg>
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/GenericCsvImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/GenericCsvImporter.cs
new file mode 100644
index 000000000..d96b773a8
--- /dev/null
+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/GenericCsvImporter.cs
@@ -0,0 +1,113 @@
+//-----------------------------------------------------------------------
+// <copyright file="GenericCsvImporter.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.ImportExport.Importers;
+
+using AliasVault.ImportExport.Models;
+using AliasVault.ImportExport.Models.Imports;
+using CsvHelper;
+using CsvHelper.Configuration;
+using System.Globalization;
+using System.Text;
+
+/// <summary>
+/// Imports credentials from a generic CSV format designed for AliasVault.
+/// </summary>
+public static class GenericCsvImporter
+{
+ /// <summary>
+ /// Gets the CSV template structure as a string that users can download.
+ /// </summary>
+ /// <returns>A CSV template with headers and example data.</returns>
+ public static string GetCsvTemplate()
+ {
+ var template = new StringBuilder();
+
+ // Add headers
+ template.AppendLine("service_name,url,username,password,totp_secret,notes");
+
+ // Add example rows
+ template.AppendLine("Gmail,https://gmail.com,[email protected],your_password,,Important email account");
+ template.AppendLine("Facebook,https://facebook.com,your.username,your_password,,Social media account");
+ template.AppendLine("GitHub,https://github.com,developer_username,your_password,your_totp_secret_here,Development platform");
+ template.AppendLine("Secure Note,,,,,\"Important information or notes without login credentials\"");
+
+ return template.ToString();
+ }
+
+ /// <summary>
+ /// Gets the CSV template as a byte array for download.
+ /// </summary>
+ /// <returns>A byte array containing the CSV template.</returns>
+ public static byte[] GetCsvTemplateBytes()
+ {
+ return Encoding.UTF8.GetBytes(GetCsvTemplate());
+ }
+
+ /// <summary>
+ /// Imports generic CSV file and converts contents to list of ImportedCredential model objects.
+ /// </summary>
+ /// <param name="fileContent">The content of the CSV file.</param>
+ /// <returns>The imported list of ImportedCredential objects.</returns>
+ public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent)
+ {
+ using var reader = new StringReader(fileContent);
+ using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));
+
+ var credentials = new List<ImportedCredential>();
+ await foreach (var record in csv.GetRecordsAsync<GenericCsvRecord>())
+ {
+ // Skip records with no service name
+ if (string.IsNullOrWhiteSpace(record.ServiceName))
+ {
+ continue;
+ }
+
+ var credential = new ImportedCredential
+ {
+ ServiceName = record.ServiceName.Trim(),
+ ServiceUrl = NormalizeUrl(record.Url),
+ Username = record.Username?.Trim(),
+ Password = record.Password?.Trim(),
+ TwoFactorSecret = record.TotpSecret?.Trim(),
+ Notes = record.Notes?.Trim()
+ };
+
+ credentials.Add(credential);
+ }
+
+ if (credentials.Count == 0)
+ {
+ throw new InvalidOperationException("No valid records found in the CSV file. Please ensure the CSV has the correct headers and at least one row with a service name.");
+ }
+
+ return credentials;
+ }
+
+ /// <summary>
+ /// Normalizes URL values from the CSV.
+ /// </summary>
+ /// <param name="url">The URL from the CSV record.</param>
+ /// <returns>The normalized URL or null if empty.</returns>
+ private static string? NormalizeUrl(string? url)
+ {
+ if (string.IsNullOrWhiteSpace(url))
+ {
+ return null;
+ }
+
+ var trimmedUrl = url.Trim();
+
+ // Return null for common placeholder values
+ if (trimmedUrl == "http://" || trimmedUrl == "https://" || trimmedUrl == "N/A" || trimmedUrl == "n/a")
+ {
+ return null;
+ }
+
+ return trimmedUrl;
+ }
+}
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/GenericCsvRecord.cs b/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/GenericCsvRecord.cs
new file mode 100644
index 000000000..ce8ddf429
--- /dev/null
+++ b/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/GenericCsvRecord.cs
@@ -0,0 +1,53 @@
+//-----------------------------------------------------------------------
+// <copyright file="GenericCsvRecord.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+using CsvHelper.Configuration.Attributes;
+
+namespace AliasVault.ImportExport.Models.Imports;
+
+/// <summary>
+/// Represents a generic CSV record for importing credentials into AliasVault.
+/// This provides a simple template structure for users who want to import from other sources.
+/// </summary>
+public class GenericCsvRecord
+{
+ /// <summary>
+ /// Gets or sets the service name (e.g., "Gmail", "Facebook").
+ /// </summary>
+ [Name("service_name")]
+ public string ServiceName { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the service URL (optional).
+ /// </summary>
+ [Name("url")]
+ public string? Url { get; set; }
+
+ /// <summary>
+ /// Gets or sets the username.
+ /// </summary>
+ [Name("username")]
+ public string? Username { get; set; }
+
+ /// <summary>
+ /// Gets or sets the password.
+ /// </summary>
+ [Name("password")]
+ public string? Password { get; set; }
+
+ /// <summary>
+ /// Gets or sets the two-factor authentication secret (TOTP).
+ /// </summary>
+ [Name("totp_secret")]
+ public string? TotpSecret { get; set; }
+
+ /// <summary>
+ /// Gets or sets any additional notes.
+ /// </summary>
+ [Name("notes")]
+ public string? Notes { get; set; }
+}