mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-18 22:36:30 +03:00
merge branch 'StrangeOfPassword'
This commit is contained in:
@@ -54,12 +54,32 @@
|
||||
<!-- Ввод мастер-пароля -->
|
||||
<StackPanel Spacing="10">
|
||||
<TextBlock Text="Master password" FontWeight="SemiBold" Foreground="Black" />
|
||||
<TextBox x:Name="PasswordBox"
|
||||
PasswordChar="*"
|
||||
Watermark="Enter password"
|
||||
Padding="10,8"/>
|
||||
|
||||
<!-- Контейнер для поля пароля и индикатора -->
|
||||
<Grid RowDefinitions="Auto,Auto">
|
||||
<TextBox x:Name="PasswordBox"
|
||||
Grid.Row="0"
|
||||
PasswordChar="*"
|
||||
Watermark="Enter password"
|
||||
Padding="10,8"/>
|
||||
|
||||
<!-- Индикатор надежности пароля -->
|
||||
<Border x:Name="PasswordStrengthIndicator"
|
||||
Grid.Row="1"
|
||||
Height="4"
|
||||
CornerRadius="2"
|
||||
Margin="0,5,0,0"
|
||||
Background="#ddd">
|
||||
<Border x:Name="PasswordStrengthFill"
|
||||
Width="0"
|
||||
Height="4"
|
||||
HorizontalAlignment="Left"
|
||||
CornerRadius="2" />
|
||||
</Border>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Подтверждение пароля -->
|
||||
<StackPanel Spacing="10">
|
||||
<TextBlock Text="Confirm password" FontWeight="SemiBold" Foreground="Black" />
|
||||
<TextBox x:Name="ConfirmPasswordBox"
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Platform.Storage;
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace KeyKeeper.Views
|
||||
{
|
||||
@@ -53,6 +56,68 @@ namespace KeyKeeper.Views
|
||||
{
|
||||
UpdateCreateButtonState();
|
||||
PasswordErrorText.IsVisible = false;
|
||||
|
||||
// Обновляем индикатор сложности пароля
|
||||
string password = PasswordBox.Text ?? "";
|
||||
UpdatePasswordStrengthIndicator(password);
|
||||
}
|
||||
|
||||
private void UpdatePasswordStrengthIndicator(string password)
|
||||
{
|
||||
if (PasswordStrengthFill == null || PasswordStrengthIndicator == null)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(password))
|
||||
{
|
||||
PasswordStrengthFill.Width = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int strength = CalculatePasswordStrength(password);
|
||||
|
||||
double maxWidth = PasswordStrengthIndicator.Bounds.Width;
|
||||
if (maxWidth <= 0) maxWidth = 200;
|
||||
|
||||
PasswordStrengthFill.Width = (strength / 100.0) * maxWidth;
|
||||
|
||||
if (strength < 20)
|
||||
{
|
||||
PasswordStrengthFill.Background = new SolidColorBrush(Colors.Red);
|
||||
}
|
||||
else if (strength < 50)
|
||||
{
|
||||
PasswordStrengthFill.Background = new SolidColorBrush(Colors.Orange);
|
||||
}
|
||||
else if (strength < 70)
|
||||
{
|
||||
PasswordStrengthFill.Background = new SolidColorBrush(Colors.Gold);
|
||||
}
|
||||
else
|
||||
{
|
||||
PasswordStrengthFill.Background = new SolidColorBrush(Colors.Green);
|
||||
}
|
||||
}
|
||||
|
||||
private int CalculatePasswordStrength(string password)
|
||||
{
|
||||
int score = 0;
|
||||
|
||||
if (password.Length >= 8) score += 20;
|
||||
if (password.Length >= 12) score += 20;
|
||||
if (password.Length >= 16) score += 15;
|
||||
|
||||
if (Regex.IsMatch(password, @"\d")) score += 10;
|
||||
|
||||
if (Regex.IsMatch(password, @"[a-z]")) score += 15;
|
||||
|
||||
if (Regex.IsMatch(password, @"[A-Z]")) score += 15;
|
||||
|
||||
if (Regex.IsMatch(password, @"[!@#$%^&*()_+\-=\[\]{};':""\\|,.<>\/?]")) score += 20;
|
||||
|
||||
var uniqueChars = new System.Collections.Generic.HashSet<char>(password).Count;
|
||||
score += Math.Min(20, uniqueChars * 2);
|
||||
|
||||
return Math.Min(100, score);
|
||||
}
|
||||
|
||||
private void UpdateCreateButtonState()
|
||||
|
||||
Reference in New Issue
Block a user