-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
George Patrut
committed
Feb 27, 2024
1 parent
fe7f2c4
commit 85789f7
Showing
4 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<ui:FluentWindow | ||
x:Class="Orderly.Views.Dialogs.PasswordGeneratorDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:Orderly.Views.Dialogs" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
Width="350" | ||
Height="280" | ||
MinHeight="0" | ||
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}" | ||
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}" | ||
ExtendsContentIntoTitleBar="True" | ||
ResizeMode="NoResize" | ||
SizeToContent="Height" | ||
WindowBackdropType="None" | ||
WindowCornerPreference="Round" | ||
WindowStartupLocation="CenterOwner" | ||
mc:Ignorable="d"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="auto" /> | ||
</Grid.RowDefinitions> | ||
<Border Padding="25,25,25,10" Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="auto" /> | ||
<RowDefinition /> | ||
<RowDefinition Height="auto" /> | ||
</Grid.RowDefinitions> | ||
<TextBlock FontSize="20" Text="Generate new password" /> | ||
<ui:PasswordBox | ||
x:Name="pbPassword" | ||
Grid.Row="1" | ||
Margin="0,20,30,20" | ||
IsReadOnly="True" /> | ||
<ui:Button | ||
Grid.Row="1" | ||
Margin="-10,0" | ||
Padding="10,5" | ||
HorizontalAlignment="Right" | ||
Background="Transparent" | ||
BorderThickness="0" | ||
Click="CopyPassword"> | ||
<ui:SymbolIcon Symbol="Copy24" /> | ||
</ui:Button> | ||
<StackPanel Grid.Row="2"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition Width="auto" /> | ||
</Grid.ColumnDefinitions> | ||
<StackPanel Width="390" HorizontalAlignment="Left"> | ||
<TextBlock Text="Length" /> | ||
<Slider | ||
x:Name="slLength" | ||
IsSnapToTickEnabled="True" | ||
Maximum="24" | ||
Minimum="4" | ||
TickPlacement="BottomRight" | ||
ValueChanged="slLength_ValueChanged" /> | ||
</StackPanel> | ||
<ui:TextBlock | ||
Grid.Column="1" | ||
Margin="0,10" | ||
VerticalAlignment="Bottom" | ||
Text="{Binding ElementName=slLength, Path=Value}" /> | ||
</Grid> | ||
<WrapPanel> | ||
<CheckBox | ||
Name="cbUpper" | ||
Checked="UpdatePassword" | ||
Content="Upper case" | ||
IsChecked="True" | ||
Unchecked="UpdatePassword" /> | ||
<CheckBox | ||
Name="cbNumbers" | ||
Checked="UpdatePassword" | ||
Content="Numbers" | ||
IsChecked="True" | ||
Unchecked="UpdatePassword" /> | ||
<CheckBox | ||
Name="cbSymbols" | ||
Checked="UpdatePassword" | ||
Content="Symbols" | ||
IsChecked="True" | ||
Unchecked="UpdatePassword" /> | ||
</WrapPanel> | ||
</StackPanel> | ||
</Grid> | ||
</Border> | ||
<Grid | ||
Grid.Row="1" | ||
Height="65" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Bottom"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width=".5*" /> | ||
<ColumnDefinition Width=".5*" /> | ||
</Grid.ColumnDefinitions> | ||
<ui:Button | ||
x:Name="btnConfirm" | ||
Grid.Column="0" | ||
Width="200" | ||
Margin="10,0" | ||
Appearance="Primary" | ||
Click="btnConfirm_Click" | ||
Content="Confirm" /> | ||
<ui:Button | ||
x:Name="btnCancel" | ||
Grid.Column="1" | ||
Width="200" | ||
Margin="10,0" | ||
Click="btnCancel_Click" | ||
Content="Cancel" /> | ||
</Grid> | ||
</Grid> | ||
</ui:FluentWindow> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Orderly.Modules; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Shapes; | ||
using Wpf.Ui.Controls; | ||
|
||
namespace Orderly.Views.Dialogs | ||
{ | ||
/// <summary> | ||
/// Interaction logic for PasswordGeneratorDialog.xaml | ||
/// </summary> | ||
public partial class PasswordGeneratorDialog : FluentWindow | ||
{ | ||
public string GeneratedPassword { get; private set; } = string.Empty; | ||
public PasswordGeneratorDialog() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void btnConfirm_Click(object sender, RoutedEventArgs e) | ||
{ | ||
GeneratedPassword = pbPassword.Text; | ||
DialogResult = true; | ||
Close(); | ||
} | ||
|
||
private void btnCancel_Click(object sender, RoutedEventArgs e) | ||
{ | ||
DialogResult = false; | ||
Close(); | ||
} | ||
|
||
private void CopyPassword(object sender, RoutedEventArgs e) | ||
{ | ||
Clipboard.SetText(GeneratedPassword); | ||
pbPassword.Focus(); | ||
pbPassword.SelectAll(); | ||
} | ||
|
||
private void UpdatePassword(object sender, RoutedEventArgs e) | ||
{ | ||
if (cbUpper is null || cbSymbols is null || cbNumbers is null || slLength is null || pbPassword is null) return; | ||
bool upperCase = cbUpper.IsChecked!.Value; | ||
bool symbols = cbSymbols.IsChecked!.Value; | ||
bool numbers = cbNumbers.IsChecked!.Value; | ||
int length = (int)slLength.Value; | ||
|
||
GeneratedPassword = PasswordGenerator.GenerateSecurePassword(length, upperCase, numbers, symbols); | ||
pbPassword.Password = GeneratedPassword; | ||
} | ||
|
||
private void slLength_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) | ||
{ | ||
UpdatePassword(this, new()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters