diff --git a/ModernKeePass/ResourceDictionaries/TextBoxWithButtonStyle.xaml b/ModernKeePass/ResourceDictionaries/TextBoxWithButtonStyle.xaml index fce5830..aa94fb4 100644 --- a/ModernKeePass/ResourceDictionaries/TextBoxWithButtonStyle.xaml +++ b/ModernKeePass/ResourceDictionaries/TextBoxWithButtonStyle.xaml @@ -8,14 +8,11 @@ - + - - - @@ -299,7 +296,7 @@ FontSize="{TemplateBinding FontSize}" Grid.Column="1" Style="{StaticResource ActionButtonStyle}" - Content="{TemplateBinding ButtonSymbol}" + Content="{TemplateBinding ButtonContent}" Command="{TemplateBinding ButtonCommand}" CommandParameter="{TemplateBinding ButtonCommandParameter}"> diff --git a/ModernKeePass/Strings/en-US/Resources.resw b/ModernKeePass/Strings/en-US/Resources.resw index bc2bd7d..fd4b024 100644 --- a/ModernKeePass/Strings/en-US/Resources.resw +++ b/ModernKeePass/Strings/en-US/Resources.resw @@ -204,8 +204,8 @@ Password - - Show password + + Hide password Create new entry @@ -564,4 +564,10 @@ Delete copied value from clipboard after how many seconds ? + + Show password + + + Random + \ No newline at end of file diff --git a/ModernKeePass/Strings/fr-FR/Resources.resw b/ModernKeePass/Strings/fr-FR/Resources.resw index dd6da85..79b1546 100644 --- a/ModernKeePass/Strings/fr-FR/Resources.resw +++ b/ModernKeePass/Strings/fr-FR/Resources.resw @@ -204,9 +204,6 @@ Mot de passe - - Afficher le mot de passe - Créer une nouvelle entrée @@ -564,4 +561,13 @@ Ajouter un champ + + Afficher le mot de passe + + + Cacher le mot de passe + + + Aléatoire + \ No newline at end of file diff --git a/ModernKeePass/ViewModels/EntryDetailVm.cs b/ModernKeePass/ViewModels/EntryDetailVm.cs index be58161..2050f9d 100644 --- a/ModernKeePass/ViewModels/EntryDetailVm.cs +++ b/ModernKeePass/ViewModels/EntryDetailVm.cs @@ -26,8 +26,6 @@ using ModernKeePass.Application.Group.Commands.AddEntry; using ModernKeePass.Application.Group.Commands.DeleteEntry; using ModernKeePass.Application.Group.Commands.RemoveEntry; using ModernKeePass.Application.Group.Queries.GetGroup; -using ModernKeePass.Application.Security.Commands.GeneratePassword; -using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity; using ModernKeePass.Domain.Enums; using ModernKeePass.Application.Group.Models; using ModernKeePass.Common; @@ -42,58 +40,7 @@ namespace ModernKeePass.ViewModels public class EntryDetailVm : ViewModelBase { public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now; - public double PasswordComplexityIndicator => _mediator.Send(new EstimatePasswordComplexityQuery {Password = Password}).GetAwaiter().GetResult(); - public double PasswordLength - { - get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.PasswordLength, 25); } - set - { - _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.PasswordLength, value); - RaisePropertyChanged(nameof(PasswordLength)); - } - } - public bool UpperCasePatternSelected - { - get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.UpperCasePattern, true); } - set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.UpperCasePattern, value); } - } - public bool LowerCasePatternSelected - { - get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.LowerCasePattern, true); } - set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.LowerCasePattern, value); } - } - public bool DigitsPatternSelected - { - get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.DigitsPattern, true); } - set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.DigitsPattern, value); } - } - public bool MinusPatternSelected - { - get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.MinusPattern, false); } - set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.MinusPattern, value); } - } - public bool UnderscorePatternSelected - { - get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.UnderscorePattern, false); } - set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.UnderscorePattern, value); } - } - public bool SpacePatternSelected - { - get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.SpacePattern, false); } - set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.SpacePattern, value); } - } - public bool SpecialPatternSelected - { - get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.SpecialPattern, true); } - set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.SpecialPattern, value); } - } - public bool BracketsPatternSelected - { - get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.BracketsPattern, false); } - set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.BracketsPattern, value); } - } - public string CustomChars { get; set; } = string.Empty; - + public string Id => SelectedItem.Id; public string ParentGroupName => _parent.Title; @@ -124,7 +71,6 @@ namespace ModernKeePass.ViewModels Set(() => SelectedItem, ref _selectedItem, value, true); if (value != null) { - //AdditionalFields = new ObservableCollection(SelectedItem.AdditionalFields); AdditionalFields = new ObservableCollection( SelectedItem.AdditionalFields.Select(f => @@ -166,13 +112,6 @@ namespace ModernKeePass.ViewModels { Set(() => AdditionalFieldSelectedIndex, ref _additionalFieldSelectedIndex, value); DeleteAdditionalField.RaiseCanExecuteChanged(); - /*if (value != -1) - { - var additionalField = AdditionalFields[value]; - Set(nameof(AdditionalFieldName), ref _additionalFieldName, additionalField.Name); - Set(nameof(AdditionalFieldValue), ref _additionalFieldValue, additionalField.IsProtected ? _cryptography.UnProtect(additionalField.Value).GetAwaiter().GetResult() : additionalField.Value); - Set(nameof(AdditionalFieldIsProtected), ref _additionalFieldIsProtected, additionalField.IsProtected); - }*/ } } @@ -207,7 +146,6 @@ namespace ModernKeePass.ViewModels SetFieldValue(nameof(Password), protectedPassword, true).ConfigureAwait(false).GetAwaiter(); RaisePropertyChanged(nameof(Password)); - RaisePropertyChanged(nameof(PasswordComplexityIndicator)); } } @@ -303,49 +241,7 @@ namespace ModernKeePass.ViewModels set { Set(() => IsEditMode, ref _isEditMode, value); } } - public bool IsRevealPassword - { - get { return _isRevealPassword; } - set { Set(() => IsRevealPassword, ref _isRevealPassword, value); } - } - - /*private string _additionalFieldName; - private string _additionalFieldValue; - private bool _additionalFieldIsProtected; - - public string AdditionalFieldName - { - get { return _additionalFieldName; } - set - { - var newName = EntryFieldName.StandardFieldNames.Contains(value) ? $"{value}_1" : value; - UpdateFieldName(_additionalFieldName, newName, AdditionalFieldValue, AdditionalFieldIsProtected).ConfigureAwait(false).GetAwaiter(); - } - } - - public string AdditionalFieldValue - { - get - { - return _additionalFieldValue; - } - set - { - SetFieldValue(AdditionalFieldName, value, AdditionalFieldIsProtected).ConfigureAwait(false).GetAwaiter(); - } - } - - public bool AdditionalFieldIsProtected - { - get { return _additionalFieldIsProtected; } - set - { - SetFieldValue(AdditionalFieldName, AdditionalFieldValue, value).ConfigureAwait(false).GetAwaiter(); - } - }*/ - public RelayCommand SaveCommand { get; } - public RelayCommand GeneratePasswordCommand { get; } public RelayCommand MoveCommand { get; } public RelayCommand RestoreCommand { get; } public RelayCommand DeleteCommand { get; } @@ -365,17 +261,15 @@ namespace ModernKeePass.ViewModels private readonly IDialogService _dialog; private readonly INotificationService _notification; private readonly IFileProxy _file; - private readonly ISettingsProxy _settings; private readonly ICryptographyClient _cryptography; private GroupVm _parent; private EntryVm _selectedItem; private int _selectedIndex; private int _additionalFieldSelectedIndex = -1; private bool _isEditMode; - private bool _isRevealPassword; private bool _isDirty; - public EntryDetailVm(IMediator mediator, INavigationService navigation, IResourceProxy resource, IDialogService dialog, INotificationService notification, IFileProxy file, ISettingsProxy settings, ICryptographyClient cryptography) + public EntryDetailVm(IMediator mediator, INavigationService navigation, IResourceProxy resource, IDialogService dialog, INotificationService notification, IFileProxy file, ICryptographyClient cryptography) { _mediator = mediator; _navigation = navigation; @@ -383,11 +277,9 @@ namespace ModernKeePass.ViewModels _dialog = dialog; _notification = notification; _file = file; - _settings = settings; _cryptography = cryptography; SaveCommand = new RelayCommand(async () => await SaveChanges(), () => Database.IsDirty); - GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword()); MoveCommand = new RelayCommand(async destination => await Move(destination), destination => _parent != null && !string.IsNullOrEmpty(destination) && destination != _parent.Id); RestoreCommand = new RelayCommand(async () => await RestoreHistory()); DeleteCommand = new RelayCommand(async () => await AskForDelete()); @@ -402,6 +294,7 @@ namespace ModernKeePass.ViewModels MessengerInstance.Register(this, _ => SaveCommand.RaiseCanExecuteChanged()); MessengerInstance.Register(this, async message => await SetFieldValue(message.FieldName, message.FieldValue, message.IsProtected)); MessengerInstance.Register(this, async message => await UpdateFieldName(message.OldName, message.NewName, message.Value, message.IsProtected)); + MessengerInstance.Register(this, message => Password = message.Password); } public async Task Initialize(string entryId) @@ -421,23 +314,6 @@ namespace ModernKeePass.ViewModels }; } - public async Task GeneratePassword() - { - Password = await _mediator.Send(new GeneratePasswordCommand - { - BracketsPatternSelected = BracketsPatternSelected, - CustomChars = CustomChars, - DigitsPatternSelected = DigitsPatternSelected, - LowerCasePatternSelected = LowerCasePatternSelected, - MinusPatternSelected = MinusPatternSelected, - PasswordLength = (int)PasswordLength, - SpacePatternSelected = SpacePatternSelected, - SpecialPatternSelected = SpecialPatternSelected, - UnderscorePatternSelected = UnderscorePatternSelected, - UpperCasePatternSelected = UpperCasePatternSelected - }); - } - public async Task AddHistory() { if (_isDirty) await _mediator.Send(new AddHistoryCommand { Entry = History[0] }); diff --git a/ModernKeePass/Views/EntryDetailPage.xaml b/ModernKeePass/Views/EntryDetailPage.xaml index 0f8c65b..25d35a3 100644 --- a/ModernKeePass/Views/EntryDetailPage.xaml +++ b/ModernKeePass/Views/EntryDetailPage.xaml @@ -8,7 +8,7 @@ xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:core="using:Microsoft.Xaml.Interactions.Core" xmlns:actions="using:ModernKeePass.Actions" - xmlns:userControls="using:ModernKeePass.Views.UserControls" + xmlns:controls="using:ModernKeePass.Views.UserControls" x:Class="ModernKeePass.Views.EntryDetailPage" mc:Ignorable="d" SizeChanged="EntryDetailPage_OnSizeChanged" @@ -16,346 +16,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -372,7 +32,7 @@ - - + - + @@ -407,19 +67,9 @@ - - - - - - - - - - - + - + @@ -427,8 +77,8 @@ - - + + @@ -470,11 +120,11 @@ - + - + - + @@ -612,7 +262,7 @@ - - + \ No newline at end of file diff --git a/ModernKeePass/Views/EntryDetailPage.xaml.cs b/ModernKeePass/Views/EntryDetailPage.xaml.cs index b72c113..b9aed16 100644 --- a/ModernKeePass/Views/EntryDetailPage.xaml.cs +++ b/ModernKeePass/Views/EntryDetailPage.xaml.cs @@ -14,7 +14,7 @@ namespace ModernKeePass.Views public sealed partial class EntryDetailPage { public EntryDetailVm Model => (EntryDetailVm) DataContext; - + public EntryDetailPage() { InitializeComponent(); @@ -29,7 +29,6 @@ namespace ModernKeePass.Views { await Model.Initialize(args.Id); Model.IsEditMode = args.IsNew; - if (args.IsNew) await Model.GeneratePassword(); } } diff --git a/ModernKeePass/Views/UserControls/HamburgerMenuUserControl.xaml b/ModernKeePass/Views/UserControls/HamburgerMenuUserControl.xaml index 5c7c133..15617b3 100644 --- a/ModernKeePass/Views/UserControls/HamburgerMenuUserControl.xaml +++ b/ModernKeePass/Views/UserControls/HamburgerMenuUserControl.xaml @@ -142,7 +142,7 @@ ButtonCommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Style="{StaticResource TextBoxWithButtonStyle}" KeyDown="NewGroupTextBox_OnKeyDown" - ButtonSymbol=""> + ButtonContent=""> diff --git a/ModernKeePass/Views/UserControls/PasswordGenerationBox.xaml b/ModernKeePass/Views/UserControls/PasswordGenerationBox.xaml new file mode 100644 index 0000000..1e3b77b --- /dev/null +++ b/ModernKeePass/Views/UserControls/PasswordGenerationBox.xaml @@ -0,0 +1,384 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ModernKeePass/Views/UserControls/PasswordGenerationBox.xaml.cs b/ModernKeePass/Views/UserControls/PasswordGenerationBox.xaml.cs new file mode 100644 index 0000000..be6e818 --- /dev/null +++ b/ModernKeePass/Views/UserControls/PasswordGenerationBox.xaml.cs @@ -0,0 +1,44 @@ +using Windows.UI.Xaml; +using ModernKeePass.ViewModels; + +// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236 + +namespace ModernKeePass.Views.UserControls +{ + public sealed partial class PasswordGenerationBox + { + public string Password + { + get { return (string)GetValue(PasswordProperty); } + set { SetValue(PasswordProperty, value); } + } + public static readonly DependencyProperty PasswordProperty = + DependencyProperty.Register( + nameof(Password), + typeof(string), + typeof(PasswordGenerationBox), + new PropertyMetadata(string.Empty, (o, args) => + { + var passwordGenerationBox = o as PasswordGenerationBox; + var vm = passwordGenerationBox?.StackPanel.DataContext as PasswordGenerationBoxControlVm; + if (vm != null) vm.Password = args.NewValue.ToString(); + })); + + public string PlaceholderText + { + get { return (string)GetValue(PlaceholderTextProperty); } + set { SetValue(PlaceholderTextProperty, value); } + } + public static readonly DependencyProperty PlaceholderTextProperty = + DependencyProperty.Register( + nameof(PlaceholderText), + typeof(string), + typeof(PasswordGenerationBox), + new PropertyMetadata(string.Empty, (o, args) => { })); + + public PasswordGenerationBox() + { + InitializeComponent(); + } + } +} diff --git a/ModernKeePass/Views/UserControls/SetCredentialsUserControl.xaml b/ModernKeePass/Views/UserControls/SetCredentialsUserControl.xaml index 500d988..6a262d3 100644 --- a/ModernKeePass/Views/UserControls/SetCredentialsUserControl.xaml +++ b/ModernKeePass/Views/UserControls/SetCredentialsUserControl.xaml @@ -7,10 +7,11 @@ xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:core="using:Microsoft.Xaml.Interactions.Core" xmlns:converters="using:ModernKeePass.Converters" + xmlns:userControls="using:ModernKeePass.Views.UserControls" mc:Ignorable="d"> - - + @@ -23,30 +24,36 @@ - - + + - - --> + + - + Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToSolidColorBrushConverter}}"/>--> HamburgerMenuUserControl.xaml + + PasswordGenerationBox.xaml + SymbolPickerUserControl.xaml @@ -317,6 +320,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/WinAppCommon/Actions/ClipboardAction.cs b/WinAppCommon/Actions/ClipboardAction.cs index 29330f3..ffec1db 100644 --- a/WinAppCommon/Actions/ClipboardAction.cs +++ b/WinAppCommon/Actions/ClipboardAction.cs @@ -42,6 +42,7 @@ namespace ModernKeePass.Actions var dataPackage = new DataPackage { RequestedOperation = DataPackageOperation.Copy }; dataPackage.SetText(IsProtected ? cryptography.UnProtect(Text).GetAwaiter().GetResult() : Text); Clipboard.SetContent(dataPackage); + Clipboard.Flush(); _dispatcher.Start(); return null; @@ -49,8 +50,14 @@ namespace ModernKeePass.Actions private void Dispatcher_Tick(object sender, object e) { - Clipboard.SetContent(null); - _dispatcher.Stop(); + try + { + Clipboard.SetContent(null); + } + finally + { + _dispatcher.Stop(); + } } } } diff --git a/WinAppCommon/Controls/PasswordBoxWithButton.cs b/WinAppCommon/Controls/PasswordBoxWithButton.cs index 14495d8..eaf53cf 100644 --- a/WinAppCommon/Controls/PasswordBoxWithButton.cs +++ b/WinAppCommon/Controls/PasswordBoxWithButton.cs @@ -8,14 +8,14 @@ namespace ModernKeePass.Controls { public event EventHandler ButtonClick; - public string ButtonSymbol + public string ButtonContent { - get { return (string)GetValue(ButtonSymbolProperty); } - set { SetValue(ButtonSymbolProperty, value); } + get { return (string)GetValue(ButtonContentProperty); } + set { SetValue(ButtonContentProperty, value); } } - public static readonly DependencyProperty ButtonSymbolProperty = + public static readonly DependencyProperty ButtonContentProperty = DependencyProperty.Register( - nameof(ButtonSymbol), + nameof(ButtonContent), typeof(string), typeof(PasswordBoxWithButton), new PropertyMetadata("", (o, args) => { })); diff --git a/WinAppCommon/Controls/PasswordGenerationBox.cs b/WinAppCommon/Controls/PasswordGenerationBox.cs new file mode 100644 index 0000000..46d9719 --- /dev/null +++ b/WinAppCommon/Controls/PasswordGenerationBox.cs @@ -0,0 +1,87 @@ +using System; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; + +namespace ModernKeePass.Controls +{ + public class PasswordGenerationBox : SearchBox + { + public event EventHandler ButtonClick; + + public string ButtonSymbol + { + get { return (string)GetValue(ButtonSymbolProperty); } + set { SetValue(ButtonSymbolProperty, value); } + } + public static readonly DependencyProperty ButtonSymbolProperty = + DependencyProperty.Register( + nameof(ButtonSymbol), + typeof(string), + typeof(PasswordGenerationBox), + new PropertyMetadata("", (o, args) => { })); + + public string ButtonTooltip + { + get { return (string)GetValue(ButtonTooltipProperty); } + set { SetValue(ButtonTooltipProperty, value); } + } + public static readonly DependencyProperty ButtonTooltipProperty = + DependencyProperty.Register( + nameof(ButtonTooltip), + typeof(string), + typeof(PasswordGenerationBox), + new PropertyMetadata(string.Empty, (o, args) => { })); + + public string Password + { + get { return (string)GetValue(PasswordProperty); } + set { SetValue(PasswordProperty, value); } + } + public static readonly DependencyProperty PasswordProperty = + DependencyProperty.Register( + nameof(Password), + typeof(string), + typeof(PasswordGenerationBox), + new PropertyMetadata(string.Empty, (o, args) => { })); + + public bool IsButtonEnabled + { + get { return (bool)GetValue(IsButtonEnabledProperty); } + set { SetValue(IsButtonEnabledProperty, value); } + } + public static readonly DependencyProperty IsButtonEnabledProperty = + DependencyProperty.Register( + nameof(IsButtonEnabled), + typeof(bool), + typeof(PasswordGenerationBox), + new PropertyMetadata(true, (o, args) => { })); + + public bool IsPasswordRevealEnabled + { + get { return (bool)GetValue(IsPasswordRevealEnabledProperty); } + set { SetValue(IsPasswordRevealEnabledProperty, value); } + } + public static readonly DependencyProperty IsPasswordRevealEnabledProperty = + DependencyProperty.Register( + nameof(IsPasswordRevealEnabled), + typeof(bool), + typeof(PasswordGenerationBox), + new PropertyMetadata(true, (o, args) => { })); + + + public PasswordGenerationBox() + { + DefaultStyleKey = typeof(PasswordGenerationBox); + } + + protected override void OnApplyTemplate() + { + base.OnApplyTemplate(); + var actionButton = GetTemplateChild("ActionButton") as Button; + if (actionButton != null) + { + actionButton.Click += (sender, e) => ButtonClick?.Invoke(sender, e); + } + } + } +} \ No newline at end of file diff --git a/WinAppCommon/Controls/TextBoxWithButton.cs b/WinAppCommon/Controls/TextBoxWithButton.cs index 24b3999..7a86bfc 100644 --- a/WinAppCommon/Controls/TextBoxWithButton.cs +++ b/WinAppCommon/Controls/TextBoxWithButton.cs @@ -9,14 +9,14 @@ namespace ModernKeePass.Controls { public event EventHandler ButtonClick; - public string ButtonSymbol + public string ButtonContent { - get { return (string)GetValue(ButtonSymbolProperty); } - set { SetValue(ButtonSymbolProperty, value); } + get { return (string)GetValue(ButtonContentProperty); } + set { SetValue(ButtonContentProperty, value); } } - public static readonly DependencyProperty ButtonSymbolProperty = + public static readonly DependencyProperty ButtonContentProperty = DependencyProperty.Register( - nameof(ButtonSymbol), + nameof(ButtonContent), typeof(string), typeof(TextBoxWithButton), new PropertyMetadata("", (o, args) => { })); diff --git a/WinAppCommon/Messages/PasswordGeneratedMessage.cs b/WinAppCommon/Messages/PasswordGeneratedMessage.cs new file mode 100644 index 0000000..c9696b6 --- /dev/null +++ b/WinAppCommon/Messages/PasswordGeneratedMessage.cs @@ -0,0 +1,7 @@ +namespace Messages +{ + public class PasswordGeneratedMessage + { + public string Password { get; set; } + } +} \ No newline at end of file diff --git a/WinAppCommon/ViewModels/UserControls/PasswordGenerationBoxControlVm.cs b/WinAppCommon/ViewModels/UserControls/PasswordGenerationBoxControlVm.cs new file mode 100644 index 0000000..2060f2b --- /dev/null +++ b/WinAppCommon/ViewModels/UserControls/PasswordGenerationBoxControlVm.cs @@ -0,0 +1,113 @@ +using System.Threading.Tasks; +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Command; +using MediatR; +using Messages; +using ModernKeePass.Application.Common.Interfaces; +using ModernKeePass.Application.Security.Commands.GeneratePassword; +using ModernKeePass.Common; + +namespace ModernKeePass.ViewModels +{ + public class PasswordGenerationBoxControlVm: ViewModelBase + { + private readonly IMediator _mediator; + private readonly ISettingsProxy _settings; + private readonly ICredentialsProxy _credentials; + private string _password; + private bool _isRevealPassword; + + public double PasswordComplexityIndicator => _credentials.EstimatePasswordComplexity(Password); + public double PasswordLength + { + get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.PasswordLength, 25); } + set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.PasswordLength, value); } + } + public bool UpperCasePatternSelected + { + get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.UpperCasePattern, true); } + set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.UpperCasePattern, value); } + } + public bool LowerCasePatternSelected + { + get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.LowerCasePattern, true); } + set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.LowerCasePattern, value); } + } + public bool DigitsPatternSelected + { + get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.DigitsPattern, true); } + set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.DigitsPattern, value); } + } + public bool MinusPatternSelected + { + get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.MinusPattern, false); } + set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.MinusPattern, value); } + } + public bool UnderscorePatternSelected + { + get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.UnderscorePattern, false); } + set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.UnderscorePattern, value); } + } + public bool SpacePatternSelected + { + get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.SpacePattern, false); } + set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.SpacePattern, value); } + } + public bool SpecialPatternSelected + { + get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.SpecialPattern, true); } + set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.SpecialPattern, value); } + } + public bool BracketsPatternSelected + { + get { return _settings.GetSetting(Constants.Settings.PasswordGenerationOptions.BracketsPattern, false); } + set { _settings.PutSetting(Constants.Settings.PasswordGenerationOptions.BracketsPattern, value); } + } + public string CustomChars { get; set; } = string.Empty; + + public string Password + { + get { return _password; } + set + { + Set(() => Password, ref _password, value); + RaisePropertyChanged(() => PasswordComplexityIndicator); + } + } + + public bool IsRevealPassword + { + get { return _isRevealPassword; } + set { Set(() => IsRevealPassword, ref _isRevealPassword, value); } + } + + public RelayCommand GeneratePasswordCommand { get; } + + public PasswordGenerationBoxControlVm(IMediator mediator, ISettingsProxy settings, ICredentialsProxy credentials) + { + _mediator = mediator; + _settings = settings; + _credentials = credentials; + + GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword()); + } + + private async Task GeneratePassword() + { + Password = await _mediator.Send(new GeneratePasswordCommand + { + BracketsPatternSelected = BracketsPatternSelected, + CustomChars = CustomChars, + DigitsPatternSelected = DigitsPatternSelected, + LowerCasePatternSelected = LowerCasePatternSelected, + MinusPatternSelected = MinusPatternSelected, + PasswordLength = (int)PasswordLength, + SpacePatternSelected = SpacePatternSelected, + SpecialPatternSelected = SpecialPatternSelected, + UnderscorePatternSelected = UnderscorePatternSelected, + UpperCasePatternSelected = UpperCasePatternSelected + }); + MessengerInstance.Send(new PasswordGeneratedMessage { Password = Password }); + } + } +} \ No newline at end of file diff --git a/WinAppCommon/ViewModels/UserControls/SetCredentialsVm.cs b/WinAppCommon/ViewModels/UserControls/SetCredentialsVm.cs index ac60b45..acf7787 100644 --- a/WinAppCommon/ViewModels/UserControls/SetCredentialsVm.cs +++ b/WinAppCommon/ViewModels/UserControls/SetCredentialsVm.cs @@ -13,7 +13,6 @@ namespace ModernKeePass.ViewModels public class SetCredentialsVm : ViewModelBase { private readonly IMediator _mediator; - private readonly ICredentialsProxy _credentials; private readonly IResourceProxy _resource; private readonly IFileProxy _file; @@ -48,10 +47,9 @@ namespace ModernKeePass.ViewModels get { return _password; } set { - _password = value; + Set(() => Password, ref _password, value); RaisePropertyChanged(nameof(IsPasswordValid)); RaisePropertyChanged(nameof(IsValid)); - RaisePropertyChanged(nameof(PasswordComplexityIndicator)); GenerateCredentialsCommand.RaiseCanExecuteChanged(); } } @@ -60,7 +58,7 @@ namespace ModernKeePass.ViewModels get { return _confirmPassword; } set { - _confirmPassword = value; + Set(() => ConfirmPassword, ref _confirmPassword, value); RaisePropertyChanged(nameof(IsPasswordValid)); RaisePropertyChanged(nameof(IsValid)); GenerateCredentialsCommand.RaiseCanExecuteChanged(); @@ -85,8 +83,6 @@ namespace ModernKeePass.ViewModels set { Set(() => KeyFileText, ref _keyFileText, value); } } - public double PasswordComplexityIndicator => _credentials.EstimatePasswordComplexity(Password); - public bool IsPasswordValid => HasPassword && Password == ConfirmPassword || !HasPassword; public bool IsKeyFileValid => HasKeyFile && !string.IsNullOrEmpty(KeyFilePath) || !HasKeyFile; public bool IsValid => HasPassword && Password == ConfirmPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath) && (HasPassword || HasKeyFile); @@ -102,10 +98,9 @@ namespace ModernKeePass.ViewModels private string _keyFilePath; private string _keyFileText; - public SetCredentialsVm(IMediator mediator, ICredentialsProxy credentials, IResourceProxy resource, IFileProxy file) + public SetCredentialsVm(IMediator mediator, IResourceProxy resource, IFileProxy file) { _mediator = mediator; - _credentials = credentials; _resource = resource; _file = file; @@ -114,6 +109,12 @@ namespace ModernKeePass.ViewModels GenerateCredentialsCommand = new RelayCommand(GenerateCredentials, () => IsValid); _keyFileText = resource.GetResourceValue("CompositeKeyDefaultKeyFile"); + + MessengerInstance.Register(this, message => + { + Password = message.Password; + ConfirmPassword = message.Password; + }); } private async Task OpenKeyFile() diff --git a/WinAppCommon/ViewModels/ViewModelLocatorCommon.cs b/WinAppCommon/ViewModels/ViewModelLocatorCommon.cs index fd2f00b..de13dc2 100644 --- a/WinAppCommon/ViewModels/ViewModelLocatorCommon.cs +++ b/WinAppCommon/ViewModels/ViewModelLocatorCommon.cs @@ -68,6 +68,7 @@ namespace ModernKeePass.ViewModels SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); @@ -84,6 +85,7 @@ namespace ModernKeePass.ViewModels public SetCredentialsVm SetCredentials => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString()); public TopMenuVm TopMenu => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString()); public ColorPickerControlVm ColorPicker => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString()); + public PasswordGenerationBoxControlVm PasswordGenerationBox => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString()); public NewVm New => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString()); public OpenVm Open => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString()); public RecentVm Recent => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString()); diff --git a/WinAppCommon/WinAppCommon.projitems b/WinAppCommon/WinAppCommon.projitems index 8858859..f438c64 100644 --- a/WinAppCommon/WinAppCommon.projitems +++ b/WinAppCommon/WinAppCommon.projitems @@ -40,6 +40,7 @@ + @@ -50,6 +51,7 @@ +