Skip to content

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

Force dates to be saved into vault with colons instead of periods for time separators (#1211)

Leendert de Borst5e2f950b7e0b
diff --git a/apps/server/AliasVault.Client/Main/Models/CredentialEdit.cs b/apps/server/AliasVault.Client/Main/Models/CredentialEdit.cs
index 2d36334e5..83575e1e8 100644
--- a/apps/server/AliasVault.Client/Main/Models/CredentialEdit.cs
+++ b/apps/server/AliasVault.Client/Main/Models/CredentialEdit.cs
@@ -123,7 +123,7 @@ public sealed class CredentialEdit
UpdatedAt = DateTime.UtcNow,
},
Alias = credentialCopy.Alias,
- AliasBirthDate = credentialCopy.Alias.BirthDate == DateTime.MinValue ? string.Empty : credentialCopy.Alias.BirthDate.ToString("yyyy-MM-dd"),
+ AliasBirthDate = credentialCopy.Alias.BirthDate == DateTime.MinValue ? string.Empty : credentialCopy.Alias.BirthDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
Attachments = credentialCopy.Attachments.ToList(),
TotpCodes = credentialCopy.TotpCodes.ToList(),
CreateDate = credentialCopy.CreatedAt,
diff --git a/apps/server/Databases/AliasClientDb/AliasClientDbContext.cs b/apps/server/Databases/AliasClientDb/AliasClientDbContext.cs
index 1b6ae878a..ab69d1c42 100644
--- a/apps/server/Databases/AliasClientDb/AliasClientDbContext.cs
+++ b/apps/server/Databases/AliasClientDb/AliasClientDbContext.cs
@@ -106,11 +106,21 @@ public class AliasClientDbContext : DbContext
// Create a value converter that maps DateTime.MinValue to an empty string and vice versa.
// This prevents an empty string in the client DB from causing a fatal exception while loading
- // Alias objects. TODO: when the birthdate field is made optional in data model, this can probably
+ // Alias objects. It also supports reading . and : as separators as pre 0.23.0 some clients were susceptible to use
+ // local culture settings which could cause the birthdate field to be either format.
+ // TODO: when the birthdate field is made optional in data model and all existing values have been converted from "yyyy-MM-dd HH.mm.ss" to "yyyy-MM-dd HH':'mm':'ss", this can probably
// be removed. But test the usecase where the birthdate field is empty string (because of browser extension error).
var emptyDateTimeConverter = new ValueConverter<DateTime, string>(
- v => v == DateTime.MinValue ? string.Empty : v.ToString("yyyy-MM-dd HH:mm:ss"),
- v => string.IsNullOrEmpty(v) ? DateTime.MinValue : DateTime.Parse(v, CultureInfo.InvariantCulture));
+ v => v == DateTime.MinValue
+ ? string.Empty
+ : v.ToString("yyyy-MM-dd HH':'mm':'ss", CultureInfo.InvariantCulture),
+ v => string.IsNullOrEmpty(v)
+ ? DateTime.MinValue
+ : DateTime.ParseExact(
+ v,
+ new[] { "yyyy-MM-dd HH':'mm':'ss", "yyyy-MM-dd HH.mm.ss" }, // Support reading . and : as separators.
+ CultureInfo.InvariantCulture,
+ DateTimeStyles.None));
modelBuilder.Entity<Alias>()
.Property(e => e.BirthDate)