11using System . ComponentModel ;
2+ using System . Text . RegularExpressions ;
23using System . Windows . Media ;
34using Upsilon . Apps . Passkey . GUI . WPF . Themes ;
45using Upsilon . Apps . Passkey . Interfaces . Models ;
@@ -10,6 +11,15 @@ public class IdentifierViewModel : INotifyPropertyChanged
1011 {
1112 private readonly IAccount _account ;
1213
14+ public static readonly Dictionary < string , string > IdentifiersTypes = new ( )
15+ {
16+ { "[Username]" , "👤" } ,
17+ { "[Email]" , "📧" } ,
18+ { "[Phone Number]" , "🖁" } ,
19+ { "[Passkey]" , "🗝" } ,
20+ { "[Authentificator App]" , "📲" } ,
21+ } ;
22+
1323 public Brush IdentifierBackground => _account . HasChanged ( "Identifiers" ) ? DarkMode . ChangedBrush : DarkMode . UnchangedBrush2 ;
1424
1525 public string Identifier
@@ -19,7 +29,16 @@ public string Identifier
1929 {
2030 if ( field != value )
2131 {
22- field = value ;
32+ if ( IdentifiersTypes . Keys . Union ( IdentifiersTypes . Values ) . All ( x => ! value . StartsWith ( x , StringComparison . CurrentCultureIgnoreCase ) ) )
33+ {
34+ value = _getIdentifierType ( value ) ;
35+ }
36+
37+ foreach ( var idType in IdentifiersTypes )
38+ {
39+ field = value . Replace ( idType . Key , idType . Value ) ;
40+ }
41+
2342 OnPropertyChanged ( nameof ( Identifier ) ) ;
2443 }
2544 }
@@ -43,5 +62,21 @@ public void Refresh()
4362 {
4463 OnPropertyChanged ( nameof ( IdentifierBackground ) ) ;
4564 }
65+
66+ private static string _getIdentifierType ( string identifier )
67+ {
68+ Regex phoneRegex = new ( @"^\+\d{1,3}[\d\s\-\.]{6,20}$" ) ;
69+ Regex emailRegex = new ( @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" ) ;
70+
71+ if ( phoneRegex . IsMatch ( identifier ) )
72+ {
73+ return "🖁" + identifier ;
74+ }
75+ if ( emailRegex . IsMatch ( identifier ) )
76+ {
77+ return "📧" + identifier ;
78+ }
79+ return "👤" + identifier ;
80+ }
4681 }
4782}
0 commit comments