Skip to content

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

Update importers to detect folders and optionally new item types (#1481)

Leendert de Borsta27d1285f0af
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
index c51b46906..5fcaaa41f 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
@@ -1,6 +1,7 @@
@inject ILogger<ImportServiceCard> Logger
@inject ItemService ItemService
@inject DbService DbService
+@inject FolderService FolderService
@inject NavigationManager NavigationManager
@inject GlobalNotificationService GlobalNotificationService
@inject HttpClient HttpClient
@@ -128,11 +129,19 @@
</div>
@if (ImportedCredentials.Count > 0)
{
- <div class="mb-4">
+ <div class="mb-4 space-y-2">
<label class="inline-flex items-center">
<input type="checkbox" @bind="ExtractFavicons" class="form-checkbox h-4 w-4 text-primary-600 rounded border-gray-300 dark:border-gray-600 dark:bg-gray-700">
<span class="ml-2 text-gray-700 dark:text-gray-300">Extract favicons for services with URLs</span>
</label>
+ @if (DetectedFolderCount > 0)
+ {
+ <label class="inline-flex items-center">
+ <input type="checkbox" @bind="ImportFolders" class="form-checkbox h-4 w-4 text-primary-600 rounded border-gray-300 dark:border-gray-600 dark:bg-gray-700">
+ <span class="ml-2 text-gray-700 dark:text-gray-300">@Localizer["ImportFoldersLabel"]</span>
+ <span class="ml-2 text-sm text-gray-500 dark:text-gray-400">(@string.Format(Localizer["FoldersDetected"], DetectedFolderCount))</span>
+ </label>
+ }
</div>
}
<div class="flex justify-end mt-6 space-x-2">
@@ -248,6 +257,9 @@
private List<ImportedCredential> ImportedCredentials { get; set; } = new();
private bool ExtractFavicons { get; set; } = true;
+ private bool ImportFolders { get; set; } = true;
+ private int DetectedFolderCount { get; set; } = 0;
+ private HashSet<string> DetectedFolderNames { get; set; } = new();
private bool IsExtractingFavicons { get; set; }
private int FaviconExtractionProgress { get; set; }
private int TotalFaviconsToExtract { get; set; }
@@ -475,7 +487,14 @@
/// </summary>
private async Task ImportCredentialsToDatabase()
{
- var items = BaseImporter.ConvertToItem(ImportedCredentials);
+ // Build folder mapping if folder import is enabled
+ Dictionary<string, Guid>? folderNameToId = null;
+ if (ImportFolders && DetectedFolderCount > 0)
+ {
+ folderNameToId = await CreateOrGetFolders();
+ }
+
+ var items = BaseImporter.ConvertToItem(ImportedCredentials, folderNameToId);
foreach (var item in items)
{
await ProcessSingleItem(item);
@@ -494,6 +513,35 @@
}
}
+ /// <summary>
+ /// Creates folders that don't exist and returns a mapping of folder names to folder IDs.
+ /// </summary>
+ private async Task<Dictionary<string, Guid>> CreateOrGetFolders()
+ {
+ var folderNameToId = new Dictionary<string, Guid>(StringComparer.OrdinalIgnoreCase);
+ var existingFolders = await FolderService.GetAllWithCountsAsync();
+
+ foreach (var folderName in DetectedFolderNames)
+ {
+ // Check if folder already exists (case-insensitive)
+ var existingFolder = existingFolders.FirstOrDefault(f =>
+ f.Name.Equals(folderName, StringComparison.OrdinalIgnoreCase));
+
+ if (existingFolder != null)
+ {
+ folderNameToId[folderName] = existingFolder.Id;
+ }
+ else
+ {
+ // Create new folder - CreateAsync returns the new folder ID directly
+ var newFolderId = await FolderService.CreateAsync(folderName);
+ folderNameToId[folderName] = newFolderId;
+ }
+ }
+
+ return folderNameToId;
+ }
+
/// <summary>
/// Processes a single item.
/// </summary>
@@ -603,7 +651,7 @@
}
/// <summary>
- /// Detects and removes duplicates from the import list.
+ /// Detects and removes duplicates from the import list, and also detects folders.
/// </summary>
private async Task DetectAndRemoveDuplicates()
{
@@ -621,6 +669,10 @@
// Remove duplicates from the import list
ImportedCredentials = ImportedCredentials.Except(duplicates).ToList();
+
+ // Detect folders in the import
+ DetectedFolderNames = BaseImporter.CollectUniqueFolderNames(ImportedCredentials);
+ DetectedFolderCount = DetectedFolderNames.Count;
}
/// <summary>
diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx
index 463424969..03c34cf70 100644
--- a/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx
+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx
@@ -86,4 +86,12 @@
<value>Import</value>
<comment>Import button text</comment>
</data>
+ <data name="ImportFoldersLabel" xml:space="preserve">
+ <value>Import folders (if available)</value>
+ <comment>Checkbox label for importing folder structure from the source password manager</comment>
+ </data>
+ <data name="FoldersDetected" xml:space="preserve">
+ <value>{0} folder(s) detected</value>
+ <comment>Info text showing number of folders detected in the import. {0} is the count</comment>
+ </data>
</root>
\ No newline at end of file
diff --git a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs
index b3feee1c1..9be45b701 100644
--- a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs
+++ b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs
@@ -11,6 +11,7 @@ using AliasClientDb;
using AliasClientDb.Models;
using AliasVault.ImportExport;
using AliasVault.ImportExport.Importers;
+using AliasVault.ImportExport.Models;
using AliasVault.UnitTests.Common;
/// <summary>
@@ -30,7 +31,7 @@ public class ImportExportTests
{
Id = new Guid("00000000-0000-0000-0000-000000000001"),
Name = "Test Service",
- ItemType = "Login",
+ ItemType = ItemType.Login,
CreatedAt = DateTime.Now,
UpdatedAt = DateTime.Now,
};
@@ -533,7 +534,7 @@ public class ImportExportTests
Assert.That(secureNoteCredential.TwoFactorSecret, Is.Empty);
});
- // Test credit card entry (stored as note-only credential)
+ // Test credit card entry
var creditCardCredential = importedCredentials.First(c => c.ServiceName == "Paymentcard1");
Assert.Multiple(() =>
{
@@ -541,11 +542,12 @@ public class ImportExportTests
Assert.That(creditCardCredential.ServiceUrl, Is.Null); // Should be normalized to null
Assert.That(creditCardCredential.Username, Is.Empty);
Assert.That(creditCardCredential.Password, Is.Empty);
- Assert.That(creditCardCredential.Notes, Does.Contain("NoteType:Credit Card"));
- Assert.That(creditCardCredential.Notes, Does.Contain("Name on Card:Cardname"));
- Assert.That(creditCardCredential.Notes, Does.Contain("Number:123456781234"));
- Assert.That(creditCardCredential.Notes, Does.Contain("Security Code:1234"));
- Assert.That(creditCardCredential.Notes, Does.Contain("Creditcardnotes here"));
+ Assert.That(creditCardCredential.ItemType, Is.EqualTo(ImportedItemType.Creditcard));
+ Assert.That(creditCardCredential.Creditcard, Is.Not.Null);
+ Assert.That(creditCardCredential.Creditcard!.CardholderName, Is.EqualTo("Cardname"));
+ Assert.That(creditCardCredential.Creditcard.Number, Is.EqualTo("123456781234"));
+ Assert.That(creditCardCredential.Creditcard.Cvv, Is.EqualTo("1234"));
+ Assert.That(creditCardCredential.Notes, Is.EqualTo("Creditcardnotes here")); // Extracted notes
Assert.That(creditCardCredential.TwoFactorSecret, Is.Empty);
});
}
@@ -758,6 +760,243 @@ public class ImportExportTests
Assert.That(template, Does.Contain("your_totp_secret_here"));
}
+ /// <summary>
+ /// Test case for Bitwarden import with folder path extraction.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task ImportBitwardenWithFolders()
+ {
+ // Arrange
+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.bitwarden.csv");
+
+ // Act
+ var importedCredentials = await BitwardenImporter.ImportFromCsvAsync(fileContent);
+
+ // Assert - check folder path is extracted (6 items in Business folder in test data)
+ var businessFolderItems = importedCredentials.Where(c => c.FolderPath == "Business").ToList();
+ Assert.That(businessFolderItems, Has.Count.EqualTo(6), "Should have 6 items in Business folder");
+
+ // Verify folder names are collected correctly
+ var folderNames = BaseImporter.CollectUniqueFolderNames(importedCredentials);
+ Assert.That(folderNames, Does.Contain("Business"));
+ }
+
+ /// <summary>
+ /// Test case for multi-level folder path extraction (takes deepest folder).
+ /// </summary>
+ [Test]
+ public void ExtractDeepestFolderName()
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(BaseImporter.ExtractDeepestFolderName("Root/Business/Banking"), Is.EqualTo("Banking"));
+ Assert.That(BaseImporter.ExtractDeepestFolderName("Business"), Is.EqualTo("Business"));
+ Assert.That(BaseImporter.ExtractDeepestFolderName("Root\\Work\\Finance"), Is.EqualTo("Finance"));
+ Assert.That(BaseImporter.ExtractDeepestFolderName(string.Empty), Is.Null);
+ Assert.That(BaseImporter.ExtractDeepestFolderName(null), Is.Null);
+ Assert.That(BaseImporter.ExtractDeepestFolderName(" / "), Is.Null);
+ Assert.That(BaseImporter.ExtractDeepestFolderName("Single"), Is.EqualTo("Single"));
+ });
+ }
+
+ /// <summary>
+ /// Test case for Bitwarden type detection (login, note, card).
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task BitwardenTypeDetection()
+ {
+ // Arrange
+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.bitwarden.csv");
+
+ // Act
+ var importedCredentials = await BitwardenImporter.ImportFromCsvAsync(fileContent);
+ var items = BaseImporter.ConvertToItem(importedCredentials);
+
+ // Assert - verify login type items have Login item type
+ var loginItems = items.Where(i => i.ItemType == ItemType.Login).ToList();
+ Assert.That(loginItems, Has.Count.GreaterThan(0), "Should have at least one Login item");
+ }
+
+ /// <summary>
+ /// Test case for LastPass secure note detection.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task LastPassSecureNoteDetection()
+ {
+ // Arrange
+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.lastpass.csv");
+
+ // Act
+ var importedCredentials = await LastPassImporter.ImportFromCsvAsync(fileContent);
+ var items = BaseImporter.ConvertToItem(importedCredentials);
+
+ // Assert - verify secure note is detected
+ var secureNoteItem = items.FirstOrDefault(i => i.Name == "securenote1");
+ Assert.That(secureNoteItem, Is.Not.Null, "Should find securenote1");
+ Assert.That(secureNoteItem!.ItemType, Is.EqualTo(ItemType.Note), "Secure note should have Note item type");
+ }
+
+ /// <summary>
+ /// Test case for LastPass credit card detection and parsing.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task LastPassCreditCardDetectionAndParsing()
+ {
+ // Arrange
+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.lastpass.csv");
+
+ // Act
+ var importedCredentials = await LastPassImporter.ImportFromCsvAsync(fileContent);
+
+ // Assert - verify credit card is detected
+ var creditCardCredential = importedCredentials.FirstOrDefault(c => c.ServiceName == "Paymentcard1");
+ Assert.That(creditCardCredential, Is.Not.Null, "Should find Paymentcard1");
+ Assert.That(creditCardCredential!.ItemType, Is.EqualTo(ImportedItemType.Creditcard), "Should be Creditcard type");
+ Assert.That(creditCardCredential.Creditcard, Is.Not.Null, "Should have Creditcard data");
+ Assert.That(creditCardCredential.Creditcard!.CardholderName, Is.EqualTo("Cardname"));
+ Assert.That(creditCardCredential.Creditcard.Number, Is.EqualTo("123456781234"));
+ Assert.That(creditCardCredential.Creditcard.Cvv, Is.EqualTo("1234"));
+
+ // Convert to item and verify fields
+ var items = BaseImporter.ConvertToItem([creditCardCredential]);
+ var creditCardItem = items[0];
+ Assert.That(creditCardItem.ItemType, Is.EqualTo(ItemType.CreditCard));
+
+ var cardNumber = creditCardItem.FieldValues.FirstOrDefault(fv => fv.FieldKey == FieldKey.CardNumber);
+ Assert.That(cardNumber?.Value, Is.EqualTo("123456781234"));
+
+ var cardholderName = creditCardItem.FieldValues.FirstOrDefault(fv => fv.FieldKey == FieldKey.CardCardholderName);
+ Assert.That(cardholderName?.Value, Is.EqualTo("Cardname"));
+ }
+
+ /// <summary>
+ /// Test case for LastPass folder (grouping) import.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task LastPassFolderImport()
+ {
+ // Arrange
+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.lastpass.csv");
+
+ // Act
+ var importedCredentials = await LastPassImporter.ImportFromCsvAsync(fileContent);
+
+ // Assert - verify folder path is extracted
+ var credentialWithFolder = importedCredentials.FirstOrDefault(c => !string.IsNullOrEmpty(c.FolderPath));
+ Assert.That(credentialWithFolder, Is.Not.Null, "Should have at least one credential with folder");
+ Assert.That(credentialWithFolder!.FolderPath, Is.EqualTo("examplefolder"));
+ }
+
+ /// <summary>
+ /// Test case for KeePassXC group (folder) import.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task KeePassXcGroupImport()
+ {
+ // Arrange
+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.keepassxc.csv");
+
+ // Act
+ var importedCredentials = await KeePassXcImporter.ImportFromCsvAsync(fileContent);
+
+ // Assert - verify folder path is extracted (KeePassXC uses Group column which contains folder hierarchy)
+ var folderNames = BaseImporter.CollectUniqueFolderNames(importedCredentials);
+ Assert.That(folderNames, Has.Count.GreaterThanOrEqualTo(0), "Should collect any folders present");
+ }
+
+ /// <summary>
+ /// Test case for folder assignment during ConvertToItem.
+ /// </summary>
+ [Test]
+ public void ConvertToItemWithFolderMapping()
+ {
+ // Arrange
+ var credentials = new List<AliasVault.ImportExport.Models.ImportedCredential>
+ {
+ new()
+ {
+ ServiceName = "Test Service",
+ FolderPath = "Work/Projects",
+ Username = "user1",
+ Password = "pass1",
+ },
+ new()
+ {
+ ServiceName = "Test Service 2",
+ FolderPath = "Personal",
+ Username = "user2",
+ Password = "pass2",
+ },
+ new()
+ {
+ ServiceName = "No Folder",
+ Username = "user3",
+ Password = "pass3",
+ },
+ };
+
+ var folderMapping = new Dictionary<string, Guid>
+ {
+ { "Projects", Guid.NewGuid() }, // Deepest folder from "Work/Projects"
+ { "Personal", Guid.NewGuid() },
+ };
+
+ // Act
+ var items = BaseImporter.ConvertToItem(credentials, folderMapping);
+
+ // Assert
+ Assert.That(items[0].FolderId, Is.EqualTo(folderMapping["Projects"]), "Should assign Projects folder");
+ Assert.That(items[1].FolderId, Is.EqualTo(folderMapping["Personal"]), "Should assign Personal folder");
+ Assert.That(items[2].FolderId, Is.Null, "Should have no folder");
+ }
+
+ /// <summary>
+ /// Test case for ProtonPass type and vault (folder) import.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task ProtonPassTypeAndVaultImport()
+ {
+ // Arrange
+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.protonpass.csv");
+
+ // Act
+ var importedCredentials = await ProtonPassImporter.ImportFromCsvAsync(fileContent);
+
+ // Assert - verify vault (folder) is extracted
+ var credentialsWithVault = importedCredentials.Where(c => !string.IsNullOrEmpty(c.FolderPath)).ToList();
+ Assert.That(credentialsWithVault.Count, Is.GreaterThan(0), "Should have credentials with vault/folder");
+
+ // Verify type detection
+ var loginCredential = importedCredentials.FirstOrDefault(c => c.ItemType == ImportedItemType.Login);
+ Assert.That(loginCredential, Is.Not.Null, "Should have at least one Login type");
+ }
+
+ /// <summary>
+ /// Test case for Dashlane category (folder) import.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task DashlaneCategoryImport()
+ {
+ // Arrange
+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.dashlane.csv");
+
+ // Act
+ var importedCredentials = await DashlaneImporter.ImportFromCsvAsync(fileContent);
+
+ // Assert - check if any credentials have folder path from category
+ // Note: Dashlane test data may or may not have categories
+ var folderNames = BaseImporter.CollectUniqueFolderNames(importedCredentials);
+ Assert.That(folderNames, Is.Not.Null, "Should return a set (even if empty)");
+ }
+
/// <summary>
/// Helper method to add a field value to an item.
/// </summary>
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs
index cb4433192..b0cf7ade9 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs
@@ -142,8 +142,9 @@ public static class BaseImporter
/// Converts a list of imported credentials to a list of AliasVault Items.
/// </summary>
/// <param name="importedCredentials">The list of imported credentials.</param>
+ /// <param name="folderNameToId">Optional dictionary mapping folder names to folder IDs for folder import.</param>
/// <returns>The list of AliasVault Items.</returns>
- public static List<Item> ConvertToItem(List<ImportedCredential> importedCredentials)
+ public static List<Item> ConvertToItem(List<ImportedCredential> importedCredentials, Dictionary<string, Guid>? folderNameToId = null)
{
var items = new List<Item>();
@@ -154,27 +155,43 @@ public static class BaseImporter
var createdAt = importedCredential.CreatedAt ?? currentDateTime;
var updatedAt = importedCredential.UpdatedAt ?? currentDateTime;
- // Determine if this is an Alias item type (has alias identity data)
- var hasAliasData = importedCredential.Alias != null &&
- (!string.IsNullOrEmpty(importedCredential.Alias.FirstName) ||
- !string.IsNullOrEmpty(importedCredential.Alias.LastName) ||
- !string.IsNullOrEmpty(importedCredential.Alias.Gender) ||
- importedCredential.Alias.BirthDate.HasValue);
+ // Determine the item type (uses ItemType from importer if set)
+ var itemType = DetermineItemType(importedCredential);
var item = new Item
{
Id = Guid.NewGuid(),
Name = importedCredential.ServiceName ?? string.Empty,
- ItemType = hasAliasData ? "Alias" : "Login",
+ ItemType = itemType,
CreatedAt = createdAt,
UpdatedAt = updatedAt,
};
- // Add field values for non-empty fields
- AddFieldValueIfNotEmpty(item, FieldKey.LoginUrl, importedCredential.ServiceUrl, createdAt, updatedAt);
- AddFieldValueIfNotEmpty(item, FieldKey.LoginUsername, importedCredential.Username, createdAt, updatedAt);
- AddFieldValueIfNotEmpty(item, FieldKey.LoginPassword, importedCredential.Password, createdAt, updatedAt);
- AddFieldValueIfNotEmpty(item, FieldKey.LoginEmail, importedCredential.Email, createdAt, updatedAt);
+ // Handle folder assignment if folder mapping is provided
+ if (folderNameToId != null && !string.IsNullOrWhiteSpace(importedCredential.FolderPath))
+ {
+ var folderName = ExtractDeepestFolderName(importedCredential.FolderPath);
+ if (!string.IsNullOrWhiteSpace(folderName) && folderNameToId.TryGetValue(folderName, out var folderId))
+ {
+ item.FolderId = folderId;
+ }
+ }
+
+ // Handle credit card type - parse structured notes and add card fields
+ if (itemType == ItemType.CreditCard)
+ {
+ AddCreditCardFields(item, importedCredential, createdAt, updatedAt);
+ }
+ else
+ {
+ // Add standard field values for non-empty fields (Login, Alias, Note types)
+ AddFieldValueIfNotEmpty(item, FieldKey.LoginUrl, importedCredential.ServiceUrl, createdAt, updatedAt);
+ AddFieldValueIfNotEmpty(item, FieldKey.LoginUsername, importedCredential.Username, createdAt, updatedAt);
+ AddFieldValueIfNotEmpty(item, FieldKey.LoginPassword, importedCredential.Password, createdAt, updatedAt);
+ AddFieldValueIfNotEmpty(item, FieldKey.LoginEmail, importedCredential.Email, createdAt, updatedAt);
+ }
+
+ // Add notes for all item types
AddFieldValueIfNotEmpty(item, FieldKey.NotesContent, importedCredential.Notes, createdAt, updatedAt);
// Add alias fields if present
@@ -220,6 +237,123 @@ public static class BaseImporter
return items;
}
+ /// <summary>
+ /// Determines the item type based on the imported credential.
+ /// Uses ItemType if set by the importer, otherwise checks for alias data.
+ /// </summary>
+ /// <param name="credential">The imported credential to analyze.</param>
+ /// <returns>The item type constant from <see cref="ItemType"/>.</returns>
+ private static string DetermineItemType(ImportedCredential credential)
+ {
+ // If the importer explicitly set a type, use it
+ if (credential.ItemType.HasValue)
+ {
+ // If Login type was set but has alias data, upgrade to Alias
+ if (credential.ItemType == ImportedItemType.Login && HasAliasData(credential))
+ {
+ return ItemType.Alias;
+ }
+
+ return credential.ItemType.Value switch
+ {
+ ImportedItemType.Login => ItemType.Login,
+ ImportedItemType.Note => ItemType.Note,
+ ImportedItemType.Creditcard => ItemType.CreditCard,
+ ImportedItemType.Alias => ItemType.Alias,
+ _ => ItemType.Login,
+ };
+ }
+
+ // Fallback: check for alias data
+ if (HasAliasData(credential))
+ {
+ return ItemType.Alias;
+ }
+
+ // Default to Login
+ return ItemType.Login;
+ }
+
+ /// <summary>
+ /// Checks if the credential has alias identity data.
+ /// </summary>
+ private static bool HasAliasData(ImportedCredential credential)
+ {
+ return credential.Alias != null &&
+ (!string.IsNullOrEmpty(credential.Alias.FirstName) ||
+ !string.IsNullOrEmpty(credential.Alias.LastName) ||
+ !string.IsNullOrEmpty(credential.Alias.Gender) ||
+ credential.Alias.BirthDate.HasValue);
+ }
+
+ /// <summary>
+ /// Extracts the deepest (most specific) folder name from a potentially hierarchical path.
+ /// For example: "Root/Business/Banking" returns "Banking".
+ /// </summary>
+ /// <param name="folderPath">The folder path, potentially with hierarchy separators.</param>
+ /// <returns>The deepest folder name.</returns>
+ public static string? ExtractDeepestFolderName(string? folderPath)
+ {
+ if (string.IsNullOrWhiteSpace(folderPath))
+ {
+ return null;
+ }
+
+ // Handle common hierarchy separators: / and \
+ var separators = new[] { '/', '\\' };
+ var parts = folderPath.Split(separators, StringSplitOptions.RemoveEmptyEntries);
+
+ // Return the last (deepest) part, or null if no valid folder name
+ if (parts.Length == 0)
+ {
+ return null;
+ }
+
+ var result = parts[^1].Trim();
+ return string.IsNullOrEmpty(result) ? null : result;
+ }
+
+ /// <summary>
+ /// Collects unique folder names from imported credentials for folder creation.
+ /// </summary>
+ /// <param name="credentials">The list of imported credentials.</param>
+ /// <returns>A set of unique folder names (deepest level only).</returns>
+ public static HashSet<string> CollectUniqueFolderNames(List<ImportedCredential> credentials)
+ {
+ var folderNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
+
+ foreach (var credential in credentials)
+ {
+ var folderName = ExtractDeepestFolderName(credential.FolderPath);
+ if (!string.IsNullOrWhiteSpace(folderName))
+ {
+ folderNames.Add(folderName);
+ }
+ }
+
+ return folderNames;
+ }
+
+ /// <summary>
+ /// Adds credit card fields to an item from the ImportedCreditcard model.
+ /// Each importer is responsible for populating the Creditcard property.
+ /// </summary>
+ private static void AddCreditCardFields(Item item, ImportedCredential credential, DateTime createdAt, DateTime updatedAt)
+ {
+ if (credential.Creditcard == null)
+ {
+ return;
+ }
+
+ var card = credential.Creditcard;
+ AddFieldValueIfNotEmpty(item, FieldKey.CardCardholderName, card.CardholderName, createdAt, updatedAt);
+ AddFieldValueIfNotEmpty(item, FieldKey.CardNumber, card.Number, createdAt, updatedAt);
+ AddFieldValueIfNotEmpty(item, FieldKey.CardCvv, card.Cvv, createdAt, updatedAt);
+ AddFieldValueIfNotEmpty(item, FieldKey.CardPin, card.Pin, createdAt, updatedAt);
+ AddFieldValueIfNotEmpty(item, FieldKey.CardExpiryMonth, card.ExpiryMonth, createdAt, updatedAt);
+ AddFieldValueIfNotEmpty(item, FieldKey.CardExpiryYear, card.ExpiryYear, createdAt, updatedAt);
+ }
+
/// <summary>
/// Adds a field value to an item if the value is not empty.
/// </summary>
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenImporter.cs
index 2d54bfef9..4758b3a60 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenImporter.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenImporter.cs
@@ -37,7 +37,9 @@ public static class BitwardenImporter
Username = record.Username,
Password = record.Password,
TwoFactorSecret = record.OTPAuth,
- Notes = record.Notes
+ Notes = record.Notes,
+ FolderPath = string.IsNullOrWhiteSpace(record.Folder) ? null : record.Folder,
+ ItemType = MapBitwardenType(record.Type),
};
credentials.Add(credential);
@@ -45,4 +47,25 @@ public static class BitwardenImporter
return credentials;
}
+
+ /// <summary>
+ /// Maps Bitwarden type values to ImportedItemType.
+ /// Bitwarden types: login, note, card, identity.
+ /// </summary>
+ private static ImportedItemType? MapBitwardenType(string? bitwardenType)
+ {
+ if (string.IsNullOrWhiteSpace(bitwardenType))
+ {
+ return null;
+ }
+
+ return bitwardenType.ToLowerInvariant() switch
+ {
+ "login" => ImportedItemType.Login,
+ "note" or "securenote" => ImportedItemType.Note,
+ "card" => ImportedItemType.Creditcard,
+ "identity" => ImportedItemType.Alias,
+ _ => ImportedItemType.Login,
+ };
+ }
}
\ No newline at end of file
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/DashlaneImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/DashlaneImporter.cs
index ecaf13266..d67de23c6 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/DashlaneImporter.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/DashlaneImporter.cs
@@ -34,7 +34,8 @@ public static class DashlaneImporter
Username = record.Username,
Password = record.Password,
TwoFactorSecret = record.OTPUrl,
- Notes = BuildNotes(record)
+ Notes = BuildNotes(record),
+ FolderPath = string.IsNullOrWhiteSpace(record.Category) ? null : record.Category,
};
credentials.Add(credential);
@@ -62,11 +63,6 @@ public static class DashlaneImporter
notes.Add($"Alternative username 2: {record.Username3}");
}
- if (!string.IsNullOrEmpty(record.Category))
- {
- notes.Add($"Category: {record.Category}");
- }
-
return notes.Count > 0 ? string.Join(Environment.NewLine, notes) : null;
}
}
\ No newline at end of file
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassXcImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassXcImporter.cs
index 704221352..04b47a9e4 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassXcImporter.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/KeePassXcImporter.cs
@@ -34,7 +34,8 @@ public static class KeePassXcImporter
Username = record.Username,
Password = record.Password,
TwoFactorSecret = record.TOTP,
- Notes = record.Notes
+ Notes = record.Notes,
+ FolderPath = string.IsNullOrWhiteSpace(record.Group) ? null : record.Group,
};
credentials.Add(credential);
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.cs
index f7822b1f3..1605d6a34 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.cs
@@ -1,4 +1,4 @@
-//-----------------------------------------------------------------------
+//-----------------------------------------------------------------------
// <copyright file="LastPassImporter.cs" company="aliasvault">
// Copyright (c) aliasvault. All rights reserved.
// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
@@ -33,14 +33,42 @@ public static class LastPassImporter
continue;
}
+ // Normalize URL - LastPass uses "http://sn" for secure notes and "http://" for entries without URLs
+ var normalizedUrl = string.IsNullOrWhiteSpace(record.URL) || record.URL == "http://" || record.URL == "http://sn"
+ ? null
+ : record.URL;
+
+ // Determine item type and parse structured data inline
+ ImportedItemType? itemType = null;
+ ImportedCreditcard? creditcard = null;
+ string? notes = record.Extra;
+
+ // Check for credit card (structured data in Extra field)
+ if (!string.IsNullOrEmpty(record.Extra) && record.Extra.Contains("NoteType:Credit Card"))
+ {
+ itemType = ImportedItemType.Creditcard;
+ creditcard = ParseCreditcardFromNotes(record.Extra);
+ notes = ExtractNotesFromCreditcard(record.Extra);
+ }
+ // Check for secure note: URL is "http://sn" and no username/password
+ else if (record.URL == "http://sn" &&
+ string.IsNullOrEmpty(record.Username) &&
+ string.IsNullOrEmpty(record.Password))
+ {
+ itemType = ImportedItemType.Note;
+ }
+
var credential = new ImportedCredential
{
ServiceName = record.Title,
- ServiceUrl = NormalizeUrl(record.URL),
+ ServiceUrl = normalizedUrl,
Username = record.Username,
Password = record.Password,
TwoFactorSecret = record.TwoFactorSecret,
- Notes = record.Extra
+ Notes = notes,
+ FolderPath = string.IsNullOrWhiteSpace(record.Grouping) ? null : record.Grouping,
+ ItemType = itemType,
+ Creditcard = creditcard,
};
credentials.Add(credential);
@@ -50,18 +78,101 @@ public static class LastPassImporter
}
/// <summary>
- /// Normalizes URL values from LastPass CSV format.
- /// LastPass uses "http://sn" for secure notes and "http://" for entries without URLs.
+ /// Parses credit card data from LastPass structured notes format.
/// </summary>
- /// <param name="url">The URL from the CSV record.</param>
- /// <returns>The normalized URL or null if it's a special LastPass placeholder.</returns>
- private static string? NormalizeUrl(string? url)
+ private static ImportedCreditcard ParseCreditcardFromNotes(string notes)
{
- if (string.IsNullOrWhiteSpace(url) || url == "http://" || url == "http://sn")
+ var creditcard = new ImportedCreditcard();
+ var lines = notes.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
+
+ foreach (var line in lines)
{
- return null;
+ var colonIndex = line.IndexOf(':');
+ if (colonIndex <= 0)
+ {
+ continue;
+ }
+
+ var key = line[..colonIndex].Trim();
+ var value = line[(colonIndex + 1)..].Trim();
+
+ if (string.IsNullOrEmpty(value))
+ {
+ continue;
+ }
+
+ switch (key)
+ {
+ case "Name on Card":
+ creditcard.CardholderName = value;
+ break;
+ case "Number":
+ creditcard.Number = value;
+ break;
+ case "Security Code":
+ creditcard.Cvv = value;
+ break;
+ case "Expiration Date":
+ // LastPass format: "May,2028"
+ var parts = value.Split(',');
+ if (parts.Length == 2)
+ {
+ creditcard.ExpiryMonth = parts[0].Trim().ToLowerInvariant() switch
+ {
+ "january" => "01",
+ "february" => "02",
+ "march" => "03",
+ "april" => "04",
+ "may" => "05",
+ "june" => "06",
+ "july" => "07",
+ "august" => "08",
+ "september" => "09",
+ "october" => "10",
+ "november" => "11",
+ "december" => "12",
+ _ => null,
+ };
+ creditcard.ExpiryYear = parts[1].Trim();
+ }
+
+ break;
+ }
+ }
+
+ return creditcard;
+ }
+
+ /// <summary>
+ /// Extracts the actual notes from a LastPass credit card structured note.
+ /// The notes section is after the "Notes:" line.
+ /// </summary>
+ private static string? ExtractNotesFromCreditcard(string structuredNotes)
+ {
+ var lines = structuredNotes.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
+ var foundNotesSection = false;
+ var noteLines = new List<string>();
+
+ foreach (var line in lines)
+ {
+ if (line.StartsWith("Notes:"))
+ {
+ foundNotesSection = true;
+ var noteValue = line["Notes:".Length..].Trim();
+ if (!string.IsNullOrEmpty(noteValue))
+ {
+ noteLines.Add(noteValue);
+ }
+
+ continue;
+ }
+
+ if (foundNotesSection)
+ {
+ noteLines.Add(line);
+ }
}
- return url;
+ return noteLines.Count > 0 ? string.Join(Environment.NewLine, noteLines) : null;
}
}
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePasswordImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePasswordImporter.cs
index fd78bc554..b57238122 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePasswordImporter.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePasswordImporter.cs
@@ -34,7 +34,8 @@ public static class OnePasswordImporter
Username = record.Username,
Password = record.Password,
TwoFactorSecret = record.OTPAuth,
- Notes = record.Notes
+ Notes = record.Notes,
+ FolderPath = string.IsNullOrWhiteSpace(record.Tags) ? null : record.Tags,
};
credentials.Add(credential);
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassImporter.cs
index 7d5a1dd50..98f93a779 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassImporter.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassImporter.cs
@@ -36,6 +36,8 @@ public static class ProtonPassImporter
Password = record.Password,
Notes = record.Note,
TwoFactorSecret = record.Totp,
+ FolderPath = string.IsNullOrWhiteSpace(record.Vault) ? null : record.Vault,
+ ItemType = MapProtonPassType(record.Type),
};
credentials.Add(credential);
@@ -43,4 +45,25 @@ public static class ProtonPassImporter
return credentials;
}
+
+ /// <summary>
+ /// Maps ProtonPass type values to ImportedItemType.
+ /// ProtonPass types: login, note, alias, creditCard.
+ /// </summary>
+ private static ImportedItemType? MapProtonPassType(string? protonPassType)
+ {
+ if (string.IsNullOrWhiteSpace(protonPassType))
+ {
+ return null;
+ }
+
+ return protonPassType.ToLowerInvariant() switch
+ {
+ "login" => ImportedItemType.Login,
+ "note" => ImportedItemType.Note,
+ "alias" => ImportedItemType.Login, // ProtonPass alias is email alias, not identity alias
+ "creditcard" => ImportedItemType.Creditcard,
+ _ => ImportedItemType.Login,
+ };
+ }
}
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCredential.cs b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCredential.cs
index efc915290..a06fa1262 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCredential.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCredential.cs
@@ -68,4 +68,22 @@ public class ImportedCredential
/// Gets or sets the alias information.
/// </summary>
public ImportedAlias? Alias { get; set; }
+
+ /// <summary>
+ /// Gets or sets the folder path from the source (e.g., "Business" or "Personal/Work").
+ /// For multi-level paths, the deepest folder will be used during import.
+ /// </summary>
+ public string? FolderPath { get; set; }
+
+ /// <summary>
+ /// Gets or sets the item type. Each importer is responsible for setting this based on the source data.
+ /// If null, defaults to Login or Alias (if alias data is present).
+ /// </summary>
+ public ImportedItemType? ItemType { get; set; }
+
+ /// <summary>
+ /// Gets or sets credit card information if the item is a credit card type.
+ /// Each importer should populate this from its own format.
+ /// </summary>
+ public ImportedCreditcard? Creditcard { get; set; }
}
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCreditcard.cs b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCreditcard.cs
new file mode 100644
index 000000000..3dd8f2421
--- /dev/null
+++ b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCreditcard.cs
@@ -0,0 +1,45 @@
+//-----------------------------------------------------------------------
+// <copyright file="ImportedCreditcard.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.ImportExport.Models;
+
+/// <summary>
+/// Represents credit card information in an intermediary format that is imported from various sources.
+/// Each importer is responsible for populating this from its own format.
+/// </summary>
+public class ImportedCreditcard
+{
+ /// <summary>
+ /// Gets or sets the cardholder name.
+ /// </summary>
+ public string? CardholderName { get; set; }
+
+ /// <summary>
+ /// Gets or sets the card number.
+ /// </summary>
+ public string? Number { get; set; }
+
+ /// <summary>
+ /// Gets or sets the expiry month (01-12).
+ /// </summary>
+ public string? ExpiryMonth { get; set; }
+
+ /// <summary>
+ /// Gets or sets the expiry year (e.g., "2028").
+ /// </summary>
+ public string? ExpiryYear { get; set; }
+
+ /// <summary>
+ /// Gets or sets the CVV/security code.
+ /// </summary>
+ public string? Cvv { get; set; }
+
+ /// <summary>
+ /// Gets or sets the PIN.
+ /// </summary>
+ public string? Pin { get; set; }
+}
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedItemType.cs b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedItemType.cs
new file mode 100644
index 000000000..474f3c0a1
--- /dev/null
+++ b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedItemType.cs
@@ -0,0 +1,35 @@
+//-----------------------------------------------------------------------
+// <copyright file="ImportedItemType.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.ImportExport.Models;
+
+/// <summary>
+/// Represents the type of item being imported from a password manager.
+/// Each importer is responsible for mapping its source types to these values.
+/// </summary>
+public enum ImportedItemType
+{
+ /// <summary>
+ /// Standard login credentials (username/password).
+ /// </summary>
+ Login,
+
+ /// <summary>
+ /// Secure note without login credentials.
+ /// </summary>
+ Note,
+
+ /// <summary>
+ /// Credit card information.
+ /// </summary>
+ Creditcard,
+
+ /// <summary>
+ /// Identity/alias information (name, birthdate, etc).
+ /// </summary>
+ Alias,
+}