Added password complexity indicator on new database

Database password control now inside a Border element
Save page also has a title
This commit is contained in:
2017-10-16 16:16:58 +02:00
committed by BONNEVILLE Geoffroy
parent 5497e6fc00
commit 2b8d37057c
13 changed files with 92 additions and 33 deletions

View File

@@ -1,11 +1,11 @@
<UserControl <UserControl x:Name="UserControl"
x:Class="ModernKeePass.Controls.OpenDatabaseUserControl" x:Class="ModernKeePass.Controls.OpenDatabaseUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="65" d:DesignHeight="60"
d:DesignWidth="335" Loaded="UserControl_Loaded"> d:DesignWidth="335" Loaded="UserControl_Loaded">
<UserControl.Resources> <UserControl.Resources>
<Style TargetType="PasswordBox" x:Name="PasswordBoxWithButtonStyle"> <Style TargetType="PasswordBox" x:Name="PasswordBoxWithButtonStyle">
@@ -333,7 +333,7 @@
</Style> </Style>
</UserControl.Resources> </UserControl.Resources>
<StackPanel> <StackPanel>
<PasswordBox x:Name="PasswordBox" Width="300" IsPasswordRevealButtonEnabled="True" KeyDown="PasswordBox_KeyDown" PlaceholderText="Password" Style="{StaticResource PasswordBoxWithButtonStyle}"/> <PasswordBox x:Name="PasswordBox" Password="{Binding Password, ElementName=UserControl, Mode=TwoWay}" Width="300" IsPasswordRevealButtonEnabled="True" KeyDown="PasswordBox_KeyDown" PlaceholderText="Password" Style="{StaticResource PasswordBoxWithButtonStyle}"/>
<TextBlock x:Name="StatusTextBlock" Height="32" Width="auto" Foreground="#FFBF6969" FontSize="16" FontWeight="Bold" /> <TextBlock x:Name="StatusTextBlock" Height="32" Width="auto" Foreground="#FFBF6969" FontSize="16" FontWeight="Bold" />
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View File

@@ -6,6 +6,7 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Input;
using ModernKeePass.Common; using ModernKeePass.Common;
using ModernKeePass.Events; using ModernKeePass.Events;
using ModernKeePassLib.Cryptography;
// Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236 // Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236
@@ -23,7 +24,19 @@ namespace ModernKeePass.Controls
"CreateNew", "CreateNew",
typeof(bool), typeof(bool),
typeof(OpenDatabaseUserControl), typeof(OpenDatabaseUserControl),
new PropertyMetadata(null, (o, args) => { })); new PropertyMetadata(false, (o, args) => { }));
public string Password
{
get { return (string)GetValue(PasswordProperty); }
set { SetValue(PasswordProperty, value); }
}
public static readonly DependencyProperty PasswordProperty =
DependencyProperty.Register(
"Password",
typeof(string),
typeof(OpenDatabaseUserControl),
new PropertyMetadata(string.Empty, (o, args) => { }));
public OpenDatabaseUserControl() public OpenDatabaseUserControl()
{ {

View File

@@ -0,0 +1,27 @@
using System;
using Windows.UI.Xaml.Data;
namespace ModernKeePass.Converters
{
public class ProgressBarLegalValuesConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var legalValuesOptionString = parameter as string;
var legalValuesOptions = legalValuesOptionString?.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (legalValuesOptions == null || legalValuesOptions.Length != 2) return 0;
var minValue = double.Parse(legalValuesOptions[0]);
var maxValue = double.Parse(legalValuesOptions[1]);
var count = value is double ? (double)value : 0;
if (count > maxValue) return maxValue;
if (count < minValue) return minValue;
return count;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}

View File

@@ -127,6 +127,7 @@
<Compile Include="Converters\ColorToBrushConverter.cs" /> <Compile Include="Converters\ColorToBrushConverter.cs" />
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" /> <Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
<Compile Include="Converters\PluralizationConverter.cs" /> <Compile Include="Converters\PluralizationConverter.cs" />
<Compile Include="Converters\ProgressBarLegalValuesConverter.cs" />
<Compile Include="Events\PasswordEventArgs.cs" /> <Compile Include="Events\PasswordEventArgs.cs" />
<Compile Include="Interfaces\IIsEnabled.cs" /> <Compile Include="Interfaces\IIsEnabled.cs" />
<Compile Include="MainPage.xaml.cs"> <Compile Include="MainPage.xaml.cs">
@@ -163,6 +164,7 @@
<Compile Include="ViewModels\EntryVm.cs" /> <Compile Include="ViewModels\EntryVm.cs" />
<Compile Include="ViewModels\GroupVm.cs" /> <Compile Include="ViewModels\GroupVm.cs" />
<Compile Include="ViewModels\MainVm.cs" /> <Compile Include="ViewModels\MainVm.cs" />
<Compile Include="ViewModels\NewVm.cs" />
<Compile Include="ViewModels\OpenVm.cs" /> <Compile Include="ViewModels\OpenVm.cs" />
<Compile Include="ViewModels\RecentVm.cs" /> <Compile Include="ViewModels\RecentVm.cs" />
<Compile Include="ViewModels\SaveVm.cs" /> <Compile Include="ViewModels\SaveVm.cs" />

View File

@@ -2,7 +2,6 @@
x:Class="ModernKeePass.Pages.AboutPage" x:Class="ModernKeePass.Pages.AboutPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ModernKeePass.Pages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> mc:Ignorable="d">

View File

@@ -1,30 +1,15 @@
using System; // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace ModernKeePass.Pages namespace ModernKeePass.Pages
{ {
/// <summary> /// <summary>
/// An empty page that can be used on its own or navigated to within a Frame. /// An empty page that can be used on its own or navigated to within a Frame.
/// </summary> /// </summary>
public sealed partial class AboutPage : Page public sealed partial class AboutPage
{ {
public AboutPage() public AboutPage()
{ {
this.InitializeComponent(); InitializeComponent();
} }
} }
} }

View File

@@ -9,17 +9,24 @@
xmlns:viewModels="using:ModernKeePass.ViewModels" xmlns:viewModels="using:ModernKeePass.ViewModels"
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter"/>
</Page.Resources> </Page.Resources>
<Page.DataContext> <Page.DataContext>
<viewModels:OpenVm /> <viewModels:NewVm />
</Page.DataContext> </Page.DataContext>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock Style="{StaticResource HeaderTextBlockStyle}" Margin="0,-20,0,20">New</TextBlock> <TextBlock Style="{StaticResource HeaderTextBlockStyle}" Margin="0,-20,0,20">New</TextBlock>
<HyperlinkButton Content="Create new..." Click="ButtonBase_OnClick" /> <HyperlinkButton Content="Create new..." Click="ButtonBase_OnClick" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30">Create a new password database to the location of your chosing.</TextBlock> <TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30">Create a new password database to the location of your chosing.</TextBlock>
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" /> <Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="350" Visibility="{Binding ShowPasswordBox, Converter={StaticResource BooleanToVisibilityConverter}}">
<local:OpenDatabaseUserControl HorizontalAlignment="Left" CreateNew="True" Visibility="{Binding ShowPasswordBox, Converter={StaticResource BooleanToVisibilityConverter}}" ValidationChecked="PasswordUserControl_PasswordChecked" /> <StackPanel>
<TextBlock Margin="25,10,0,10" Text="{Binding Name}" />
<local:OpenDatabaseUserControl Password="{Binding Password, Mode=TwoWay}" CreateNew="True" ValidationChecked="PasswordUserControl_PasswordChecked" />
<TextBlock Margin="25,0,0,10">Password complexity</TextBlock>
<ProgressBar Margin="25,0,0,10" Value="{Binding PasswordComplexityIndicator, ConverterParameter=0\,100, Converter={StaticResource ProgressBarLegalValuesConverter}, Mode=OneWay}" Width="300" HorizontalAlignment="Left" />
</StackPanel>
</Border>
</StackPanel> </StackPanel>
</Page> </Page>

View File

@@ -18,7 +18,7 @@ namespace ModernKeePass.Pages
{ {
private Frame _mainFrame; private Frame _mainFrame;
public OpenVm Model => (OpenVm)DataContext; public NewVm Model => (NewVm)DataContext;
public NewDatabasePage() public NewDatabasePage()
{ {

View File

@@ -21,7 +21,11 @@
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30">Open an existing password database from your PC.</TextBlock> <TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30">Open an existing password database from your PC.</TextBlock>
<HyperlinkButton Content="From Url..." IsEnabled="False" /> <HyperlinkButton Content="From Url..." IsEnabled="False" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30">Open an existing password database from an Internet location (not yet implemented).</TextBlock> <TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30">Open an existing password database from an Internet location (not yet implemented).</TextBlock>
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" /> <Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="350" Visibility="{Binding ShowPasswordBox, Converter={StaticResource BooleanToVisibilityConverter}}">
<local:OpenDatabaseUserControl HorizontalAlignment="Left" Visibility="{Binding ShowPasswordBox, Converter={StaticResource BooleanToVisibilityConverter}}" ValidationChecked="PasswordUserControl_PasswordChecked" /> <StackPanel>
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" Height="auto" Width="auto" FontSize="16" />
<local:OpenDatabaseUserControl ValidationChecked="PasswordUserControl_PasswordChecked" />
</StackPanel>
</Border>
</StackPanel> </StackPanel>
</Page> </Page>

View File

@@ -11,6 +11,7 @@
</Page.DataContext> </Page.DataContext>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock Style="{StaticResource HeaderTextBlockStyle}" Margin="0,-20,0,20">Save</TextBlock>
<HyperlinkButton Content="Save and close" Click="SaveButton_OnClick" /> <HyperlinkButton Content="Save and close" Click="SaveButton_OnClick" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30">This will save and close the currently opened database.</TextBlock> <TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30">This will save and close the currently opened database.</TextBlock>
<HyperlinkButton Content="Save as..." Click="SaveAsButton_OnClick" /> <HyperlinkButton Content="Save as..." Click="SaveAsButton_OnClick" />

View File

@@ -0,0 +1,21 @@
using ModernKeePassLib.Cryptography;
namespace ModernKeePass.ViewModels
{
public class NewVm : OpenVm
{
private string _password = string.Empty;
public string Password
{
get { return _password; }
set
{
_password = value;
NotifyPropertyChanged("PasswordComplexityIndicator");
}
}
public double PasswordComplexityIndicator => QualityEstimation.EstimatePasswordBits(Password.ToCharArray());
}
}

View File

@@ -27,7 +27,7 @@ namespace ModernKeePass.ViewModels
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName) protected void NotifyPropertyChanged(string propertyName)
{ {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }

View File

@@ -9,7 +9,7 @@ namespace ModernKeePass.ViewModels
{ {
private RecentItemVm _selectedItem; private RecentItemVm _selectedItem;
private ObservableCollection<RecentItemVm> _recentItems = new ObservableCollection<RecentItemVm>(); private ObservableCollection<RecentItemVm> _recentItems = new ObservableCollection<RecentItemVm>();
public ObservableCollection<RecentItemVm> RecentItems public ObservableCollection<RecentItemVm> RecentItems
{ {
get { return _recentItems; } get { return _recentItems; }