Password generation button with display toggle and indicator is now a user control

SetCredentials user controls now uses PasswordGenerationBox user control
Some layout improvements in EntryDetailsPage
WIP Clipboard suspend issues
This commit is contained in:
Geoffroy BONNEVILLE
2020-05-25 19:23:32 +02:00
parent 0e05e3fbca
commit 3d436c56fa
20 changed files with 727 additions and 532 deletions

View File

@@ -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 });
}
}
}

View File

@@ -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<PasswordGeneratedMessage>(this, message =>
{
Password = message.Password;
ConfirmPassword = message.Password;
});
}
private async Task OpenKeyFile()

View File

@@ -68,6 +68,7 @@ namespace ModernKeePass.ViewModels
SimpleIoc.Default.Register<SetCredentialsVm>();
SimpleIoc.Default.Register<TopMenuVm>();
SimpleIoc.Default.Register<ColorPickerControlVm>();
SimpleIoc.Default.Register<PasswordGenerationBoxControlVm>();
SimpleIoc.Default.Register<NewVm>();
SimpleIoc.Default.Register<OpenVm>();
SimpleIoc.Default.Register<RecentVm>();
@@ -84,6 +85,7 @@ namespace ModernKeePass.ViewModels
public SetCredentialsVm SetCredentials => ServiceLocator.Current.GetInstance<SetCredentialsVm>(Guid.NewGuid().ToString());
public TopMenuVm TopMenu => ServiceLocator.Current.GetInstance<TopMenuVm>(Guid.NewGuid().ToString());
public ColorPickerControlVm ColorPicker => ServiceLocator.Current.GetInstance<ColorPickerControlVm>(Guid.NewGuid().ToString());
public PasswordGenerationBoxControlVm PasswordGenerationBox => ServiceLocator.Current.GetInstance<PasswordGenerationBoxControlVm>(Guid.NewGuid().ToString());
public NewVm New => ServiceLocator.Current.GetInstance<NewVm>(Guid.NewGuid().ToString());
public OpenVm Open => ServiceLocator.Current.GetInstance<OpenVm>(Guid.NewGuid().ToString());
public RecentVm Recent => ServiceLocator.Current.GetInstance<RecentVm>(Guid.NewGuid().ToString());