Skip to content

Commit 1588ad6

Browse files
authored
Merge pull request #47 from YassinLokhat/46-add-identifier-types
46 add identifier types
2 parents 569ad54 + 3e1a22b commit 1588ad6

9 files changed

Lines changed: 105 additions & 31 deletions

.github/workflows/csharp-dotnet-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: windows-latest
11+
runs-on: windows-2025-vs2026
1212

1313
steps:
1414
- uses: actions/checkout@v4

GUI/WPF/MainWindow.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
<Window.CommandBindings>
1616
<CommandBinding Command="Open" Executed="_openDatabase_MenuItem_Click"/>
1717
<CommandBinding Command="New" Executed="_newUser_MenuItem_Click"/>
18+
<CommandBinding Command="Print" Executed="_generatePassword_MenuItem_Click"/>
1819
</Window.CommandBindings>
1920
<Window.InputBindings>
2021
<KeyBinding Key="O" Modifiers="Control" Command="Open"/>
2122
<KeyBinding Key="N" Modifiers="Control" Command="New"/>
23+
<KeyBinding Key="P" Modifiers="Control" Command="Print"/>
2224
</Window.InputBindings>
2325
<StackPanel>
2426
<Menu>
@@ -29,15 +31,13 @@
2931
</Menu.ItemsPanel>
3032
<MenuItem Header="_Open database"
3133
Command="Open"
32-
InputGestureText="Ctrl+O"
33-
Click="_openDatabase_MenuItem_Click"/>
34+
InputGestureText="Ctrl+O"/>
3435
<MenuItem Header="_New User"
3536
Command="New"
36-
InputGestureText="Ctrl+N"
37-
Click="_newUser_MenuItem_Click"/>
37+
InputGestureText="Ctrl+N"/>
3838
<MenuItem Header="_Generate random Password"
39-
HorizontalAlignment="Right"
40-
Click="_generatePassword_MenuItem_Click"/>
39+
Command="Print"
40+
HorizontalAlignment="Right"/>
4141
</Menu>
4242
<Grid>
4343
<Grid.RowDefinitions>

GUI/WPF/Upsilon.Apps.Passkey.GUI.WPF.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<Authors>Yassin Lokhat</Authors>
1111
<Description>A local stored Password Manager GUI.</Description>
1212
<Version>3.0.0</Version>
13-
<AssemblyVersion>1.0.1</AssemblyVersion>
14-
<FileVersion>1.0.1</FileVersion>
13+
<AssemblyVersion>1.0.2</AssemblyVersion>
14+
<FileVersion>1.0.2</FileVersion>
1515
<ApplicationIcon>icon.ico</ApplicationIcon>
1616
</PropertyGroup>
1717

GUI/WPF/ViewModels/Controls/IdentifiantViewModel.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel;
2+
using System.Text.RegularExpressions;
23
using System.Windows.Media;
34
using Upsilon.Apps.Passkey.GUI.WPF.Themes;
45
using 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
}

GUI/WPF/Views/Controls/AccountView.xaml.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,20 @@ public AccountView()
2323

2424
public string? GetIdentifier()
2525
{
26-
return _identifiers_LB.SelectedItem is not IdentifierViewModel identifierViewModel ? null : identifierViewModel.Identifier;
26+
string? identifier = _identifiers_LB.SelectedItem is not IdentifierViewModel identifierViewModel ? null : identifierViewModel.Identifier;
27+
28+
if (identifier is not null)
29+
{
30+
foreach (string idType in IdentifierViewModel.IdentifiersTypes.Values)
31+
{
32+
if (identifier.StartsWith(idType))
33+
{
34+
identifier = identifier[idType.Length..];
35+
}
36+
}
37+
}
38+
39+
return identifier;
2740
}
2841

2942
public string? GetPassword() => _viewModel?.Password;

GUI/WPF/Views/InsertIdentifierView.xaml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,37 @@
1010
Title="Insert identifier"
1111
ResizeMode="CanMinimize"
1212
WindowStartupLocation="CenterScreen"
13-
Height="200" Width="300">
13+
Height="200" Width="483">
1414
<Grid>
1515
<Grid.RowDefinitions>
16+
<RowDefinition Height="Auto"/>
1617
<RowDefinition Height="Auto"/>
1718
<RowDefinition Height="*"/>
1819
</Grid.RowDefinitions>
1920
<StackPanel Grid.Row="0"
2021
Orientation="Horizontal">
2122
<TextBox Name="_identifier_TB"
22-
Width="230"
23+
Width="415"
2324
Text="{Binding Identifier, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
2425
KeyUp="_identifier_TextBox_KeyUp"/>
25-
<Button Content=""/>
26+
<Button Content=""
27+
Click="_clearFilter_Button_Click"/>
28+
</StackPanel>
29+
<StackPanel Grid.Row="1"
30+
Orientation="Horizontal">
31+
<Button Content="Username"
32+
Click="_insertIdentifierType_Button_Click"/>
33+
<Button Content="Email"
34+
Click="_insertIdentifierType_Button_Click"/>
35+
<Button Content="Phone Number"
36+
Click="_insertIdentifierType_Button_Click"/>
37+
<Button Content="Passkey"
38+
Click="_insertIdentifierType_Button_Click"/>
39+
<Button Content="Authentificator App"
40+
Click="_insertIdentifierType_Button_Click"/>
2641
</StackPanel>
2742
<ListBox Name="_identifiers_LB"
28-
Grid.Row="1"
43+
Grid.Row="2"
2944
SelectionChanged="_identifiers_LB_SelectionChanged"/>
3045
</Grid>
3146
</Window>

GUI/WPF/Views/InsertIdentifierView.xaml.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Windows.Controls;
33
using Upsilon.Apps.Passkey.GUI.WPF.Helper;
44
using Upsilon.Apps.Passkey.GUI.WPF.ViewModels;
5+
using Upsilon.Apps.Passkey.GUI.WPF.ViewModels.Controls;
56

67
namespace Upsilon.Apps.Passkey.GUI.WPF.Views
78
{
@@ -65,5 +66,20 @@ private void _identifiers_LB_SelectionChanged(object sender, SelectionChangedEve
6566
_selectedIdentifier = _identifiers_LB.SelectedItem as string;
6667
DialogResult = true;
6768
}
69+
70+
private void _insertIdentifierType_Button_Click(object sender, RoutedEventArgs e)
71+
{
72+
string? idType = ((Button)sender).Content as string;
73+
74+
if (idType is not null)
75+
{
76+
_viewModel.Identifier = IdentifierViewModel.IdentifiersTypes[$"[{idType}]"] + _viewModel.Identifier;
77+
}
78+
}
79+
80+
private void _clearFilter_Button_Click(object sender, RoutedEventArgs e)
81+
{
82+
_viewModel.Identifier = string.Empty;
83+
}
6884
}
6985
}

GUI/WPF/Views/UserServicesView.xaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@
1717
MinWidth="1300">
1818
<Window.CommandBindings>
1919
<CommandBinding Command="Save" Executed="_save_MenuItem_Click"/>
20+
<CommandBinding Command="Print" Executed="_generateRandomPassword_MenuItem_Click"/>
21+
<CommandBinding Command="Find" Executed="_filterCommand_CommandBinding_Executed"/>
22+
<CommandBinding Command="Stop" Executed="_filterClear_Button_Click"/>
2023
</Window.CommandBindings>
2124
<Window.InputBindings>
2225
<KeyBinding Key="S" Modifiers="Control" Command="Save"/>
26+
<KeyBinding Key="P" Modifiers="Control" Command="Print"/>
27+
<KeyBinding Key="F" Modifiers="Control" Command="Find"/>
28+
<KeyBinding Key="F3" Command="Find"/>
29+
<KeyBinding Key="F" Modifiers="Control+Shift" Command="Stop"/>
30+
<KeyBinding Key="F3" Modifiers="Shift" Command="Stop"/>
2331
</Window.InputBindings>
2432
<Grid>
2533
<Grid.RowDefinitions>
@@ -34,13 +42,11 @@
3442
</ItemsPanelTemplate>
3543
</Menu.ItemsPanel>
3644
<MenuItem Header="_Save"
37-
Click="_save_MenuItem_Click"
38-
Command="Save"
39-
InputGestureText="Ctrl+S"/>
45+
Command="Save"/>
4046
<MenuItem Header="_User settings"
4147
Click="_userSettings_MenuItem_Click"/>
4248
<MenuItem Header="_Generate random Password"
43-
Click="_generateRandomPassword_MenuItem_Click"/>
49+
Command="Print"/>
4450
<MenuItem Header="_Show activities"
4551
Click="_showActivities_MenuItem_Click"/>
4652
<MenuItem Name="_warnings_MI"
@@ -97,7 +103,7 @@
97103
IsChecked="{Binding ChangedItemsOnly}"/>
98104
<Button Grid.Column="7"
99105
Content=""
100-
Click="_filterClear_Button_Click"/>
106+
Command="Stop"/>
101107
</Grid>
102108
</GroupBox>
103109
</StackPanel>

GUI/WPF/Views/UserServicesView.xaml.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,6 @@ private UserServicesView()
4242

4343
_ = _serviceFilter_TB.Focus();
4444

45-
CommandBinding filterCommand = new(new RoutedCommand()
46-
{
47-
InputGestures =
48-
{
49-
new KeyGesture(Key.F, ModifierKeys.Control),
50-
new KeyGesture(Key.F3),
51-
},
52-
});
53-
filterCommand.Executed += _filterCommand_CommandBinding_Executed;
54-
_ = CommandBindings.Add(filterCommand);
55-
5645
MainViewModel.Database.DatabaseClosed += _database_DatabaseClosed;
5746
MainViewModel.Database.WarningsUpdated += _database_WarningUpdated;
5847
Loaded += _userServicesView_Loaded;

0 commit comments

Comments
 (0)