Make app functional
This commit is contained in:
2 files changed
+72
-16
No files matched your search
@@ -13,18 +13,18 @@
|
||||
<MicaBackdrop />
|
||||
</Window.SystemBackdrop>
|
||||
|
||||
<Grid>
|
||||
<Grid Margin="16,0,16,0">
|
||||
<StackPanel Spacing="12" HorizontalAlignment="Center" Margin="0,36,0,0">
|
||||
<TextBlock Text="Password Generator" FontSize="24" FontWeight="Bold" TextAlignment="Center" />
|
||||
<TextBlock Text="Select a length, or use the slider for a custom value." TextAlignment="Center" />
|
||||
<TextBlock Text="Password Length: 0" TextAlignment="Center" Margin="0,12,0,0" />
|
||||
<Slider x:Name="LengthSlider" Minimum="1" Maximum="500" Value="8" />
|
||||
<TextBlock x:Name="LengthText" Text="Password Length: 8" TextAlignment="Center" Margin="0,12,0,0" />
|
||||
<Slider x:Name="LengthSlider" Minimum="1" Maximum="500" Value="8" ValueChanged="LengthSlider_ValueChanged" />
|
||||
<StackPanel Spacing="8" HorizontalAlignment="Center" Orientation="Horizontal">
|
||||
<Button Content="8" />
|
||||
<Button Content="16" />
|
||||
<Button Content="32" />
|
||||
<Button Content="64" />
|
||||
<Button Content="128" />
|
||||
<Button x:Name="PresetLength8Button" Content="8" Click="PresetLength8Button_Click"/>
|
||||
<Button x:Name="PresetLength16Button" Content="16" Click="PresetLength16Button_Click"/>
|
||||
<Button x:Name="PresetLength32Button" Content="32" Click="PresetLength32Button_Click"/>
|
||||
<Button x:Name="PresetLength64Button" Content="64" Click="PresetLength64Button_Click"/>
|
||||
<Button x:Name="PresetLength128Button" Content="128" Click="PresetLength128Button_Click"/>
|
||||
</StackPanel>
|
||||
<TextBlock Text="Characters to use" TextAlignment="Center" Margin="0,12,0,0" />
|
||||
<Grid HorizontalAlignment="Center" ColumnSpacing="8" RowSpacing="8">
|
||||
@@ -38,15 +38,15 @@
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<CheckBox Grid.Row="0" Grid.Column="0" Content="Uppercase" IsChecked="True" />
|
||||
<CheckBox Grid.Row="0" Grid.Column="1" Content="Lowercase" IsChecked="True" />
|
||||
<CheckBox Grid.Row="1" Grid.Column="0" Content="Numbers" IsChecked="True" />
|
||||
<CheckBox Grid.Row="1" Grid.Column="1" Content="Symbols" IsChecked="True" />
|
||||
<CheckBox x:Name="UppercaseCheck" Grid.Row="0" Grid.Column="0" Content="Uppercase" IsChecked="True" Click="RegenerateButton_Click" />
|
||||
<CheckBox x:Name="LowercaseCheck" Grid.Row="0" Grid.Column="1" Content="Lowercase" IsChecked="True" Click="RegenerateButton_Click" />
|
||||
<CheckBox x:Name="NumbersCheck" Grid.Row="1" Grid.Column="0" Content="Numbers" IsChecked="True" Click="RegenerateButton_Click" />
|
||||
<CheckBox x:Name="SymbolsCheck" Grid.Row="1" Grid.Column="1" Content="Symbols" IsChecked="True" Click="RegenerateButton_Click" />
|
||||
</Grid>
|
||||
<TextBox Text="" TextAlignment="Center" TextWrapping="Wrap" IsReadOnly="True" />
|
||||
<TextBox x:Name="PasswordOutput" Text="" TextAlignment="Center" TextWrapping="Wrap" IsReadOnly="True" MaxHeight="136" ScrollViewer.VerticalScrollBarVisibility="Auto" />
|
||||
<StackPanel Spacing="8" HorizontalAlignment="Center" Orientation="Horizontal">
|
||||
<Button Content="Copy" />
|
||||
<Button Content="Regenerate" />
|
||||
<Button x:Name="CopyButton" Content="Copy" Click="CopyButton_Click" />
|
||||
<Button x:Name="RegenerateButton" Content="Regenerate" Click="RegenerateButton_Click" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using System;
|
||||
using System.Text;
|
||||
using Windows.ApplicationModel.DataTransfer;
|
||||
using WinRT.Interop;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
@@ -14,9 +16,17 @@ namespace Password_Generator
|
||||
/// </summary>
|
||||
public sealed partial class MainWindow : Window
|
||||
{
|
||||
const string charsUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const string charsLower = "abcdefghijklmnopqrstuvwxyz";
|
||||
const string charsNumber = "0123456789";
|
||||
const string charsSymbols = "!@#$%^&*";
|
||||
private bool _loaded = false;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
_loaded = true;
|
||||
GeneratePassword();
|
||||
|
||||
IntPtr hWnd = WindowNative.GetWindowHandle(this);
|
||||
WindowId windowId = Win32Interop.GetWindowIdFromWindow(hWnd);
|
||||
@@ -28,5 +38,51 @@ namespace Password_Generator
|
||||
Height = 600
|
||||
});
|
||||
}
|
||||
|
||||
public void GeneratePassword()
|
||||
{
|
||||
string chars =
|
||||
((UppercaseCheck.IsChecked ?? false) ? charsUpper : "") +
|
||||
((LowercaseCheck.IsChecked ?? false) ? charsLower : "") +
|
||||
((NumbersCheck.IsChecked ?? false) ? charsNumber : "") +
|
||||
((SymbolsCheck.IsChecked ?? false) ? charsSymbols : "");
|
||||
|
||||
if (chars == "") { PasswordOutput.Text = ""; return; }
|
||||
|
||||
StringBuilder password = new();
|
||||
Random random = new();
|
||||
|
||||
for (int i = 0; i < LengthSlider.Value; i++)
|
||||
{
|
||||
password.Append(chars[random.Next(chars.Length)]);
|
||||
}
|
||||
|
||||
PasswordOutput.Text = password.ToString();
|
||||
}
|
||||
|
||||
private void LengthSlider_ValueChanged(object sender, Microsoft.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e)
|
||||
{
|
||||
if (!_loaded) return;
|
||||
|
||||
LengthText.Text = $"Password Length: {e.NewValue}";
|
||||
GeneratePassword();
|
||||
}
|
||||
|
||||
private void CopyButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DataPackage dataPackage = new()
|
||||
{
|
||||
RequestedOperation = DataPackageOperation.Copy
|
||||
};
|
||||
dataPackage.SetText(PasswordOutput.Text);
|
||||
Clipboard.SetContent(dataPackage);
|
||||
}
|
||||
|
||||
private void RegenerateButton_Click(object sender, RoutedEventArgs e) => GeneratePassword();
|
||||
private void PresetLength8Button_Click(object sender, RoutedEventArgs e) => LengthSlider.Value = 8;
|
||||
private void PresetLength16Button_Click(object sender, RoutedEventArgs e) => LengthSlider.Value = 16;
|
||||
private void PresetLength32Button_Click(object sender, RoutedEventArgs e) => LengthSlider.Value = 32;
|
||||
private void PresetLength64Button_Click(object sender, RoutedEventArgs e) => LengthSlider.Value = 64;
|
||||
private void PresetLength128Button_Click(object sender, RoutedEventArgs e) => LengthSlider.Value = 128;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user