Skip to content

Commit

Permalink
Merge pull request #157 from Flamifly/password-chart1
Browse files Browse the repository at this point in the history
Adding/Chaning Translations for #133 and Fixed #156 in addition added Info Messages
  • Loading branch information
FrozenAssassine authored Dec 21, 2024
2 parents 3364414 + 4a2f895 commit be53b9f
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 124 deletions.
38 changes: 27 additions & 11 deletions EasePass/Controls/PasswordSafetyChart.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,33 @@ public sealed partial class PasswordSafetyChart : UserControl, INotifyPropertyCh
"Predictability".Localized("PW_SafetyChart_Predictability/Text"),
"Seen before".Localized("PW_SafetyChart_Seenbefore/Text")
};
private string[][] prefixes = new string[][]

private static string[] infos = new string[]
{
"Contains Lower case:".Localized("PW_SafetyChart_Info_LowerCase/Text"),
"Contains Upper case:".Localized("PW_SafetyChart_Info_UpperCase/Text"),
"Passwordlength:".Localized("PW_SafetyChart_Info_Passwordlength/Text"),
"Leaked or exploited:".Localized("PW_SafetyChart_Info_LeakedExploited/Text"),
"Contains Punctuation:".Localized("PW_SafetyChart_Info_Punctuation/Text"),
"Contains Digits:".Localized("PW_SafetyChart_Info_Digits/Text"),
"Predictability:".Localized("PW_SafetyChart_Info_Predictability/Text"),
"Seen before:".Localized("PW_SafetyChart_Info_SeenBefore/Text")
};
private static string[][] suffixes = new string[][]
{
//true, false, null
new string[]{ "Contains".Localized("PW_SafetyChart_Contains/Text"), "Missing".Localized("PW_SafetyChart_Missing/Text"), "Unknown whether it contains".Localized("PW_SafetyChart_UnknownContains/Text") },
new string[]{ "Contains".Localized("PW_SafetyChart_Contains/Text"), "Missing".Localized("PW_SafetyChart_Missing/Text"), "Unknown whether it contains".Localized("PW_SafetyChart_UnknownContains/Text") },
new string[]{ "Meets the minimum".Localized("PW_SafetyChart_MeetsMinimum/Text"), "Does not meet the minimum".Localized("PW_SafetyChart_DoesNotMeetMinimum/Text"), "Unknown whether it meets the minimum".Localized("PW_SafetyChart_UnknownMeetsMinimum/Text") },
new string[]{ "Not".Localized("PW_SafetyChart_Not/Text"), "Is already".Localized("PW_SafetyChart_IsAlready/Text"), "Unknown whether it has already been".Localized("PW_SafetyChart_UnknownAlready/Text") },
new string[]{ "Contains".Localized("PW_SafetyChart_Contains/Text"), "Missing".Localized("PW_SafetyChart_Missing/Text"), "Unknown whether it contains".Localized("PW_SafetyChart_UnknownContains/Text") },
new string[]{ "Contains".Localized("PW_SafetyChart_Contains/Text"), "Missing".Localized("PW_SafetyChart_Missing/Text"), "Unknown whether it contains".Localized("PW_SafetyChart_UnknownContains/Text") },
new string[]{ "Low".Localized("PW_SafetyChart_Low/Text"), "High".Localized("PW_SafetyChart_High/Text"), "Unknown ".Localized("PW_SafetyChart_Unknown/Text") },
new string[]{ "Not yet".Localized("PW_SafetyChart_NotYet/Text"), "Already".Localized("PW_SafetyChart_Already/Text"), "Unknown whether".Localized("PW_SafetyChart_UnknownWhether/Text") },
new string[]{ "True".Localized("PW_SafetyChart_Info_LowerCase_Positive/Text"), "False".Localized("PW_SafetyChart_Info_LowerCase_Negative/Text") },
new string[]{ "True".Localized("PW_SafetyChart_Info_UpperCase_Positive/Text"), "False".Localized("PW_SafetyChart_Info_UpperCase_Negative/Text") },
new string[]{ "Meets Minimum".Localized("PW_SafetyChart_Info_Passwordlength_Positive/Text"), "Doesn't meet Minimum".Localized("PW_SafetyChart_Info_Passwordlength_Negative/Text") },
new string[]{ "False".Localized("PW_SafetyChart_Info_LeakedExploited_Positive/Text"), "True".Localized("PW_SafetyChart_Info_LeakedExploited_Negative/Text") },
new string[]{ "True".Localized("PW_SafetyChart_Info_Punctuation_Positive/Text"), "False".Localized("PW_SafetyChart_Info_Punctuation_Negative/Text") },
new string[]{ "True".Localized("PW_SafetyChart_Info_Digits_Positive/Text"), "False".Localized("PW_SafetyChart_Info_Digits_Negative/Text") },
new string[]{ "Low".Localized("PW_SafetyChart_Info_Predictability_Positive/Text"), "High".Localized("PW_SafetyChart_Info_Predictability_Negative/Text") },
new string[]{ "False".Localized("PW_SafetyChart_Info_SeenBefore_Positive/Text"), "True".Localized("PW_SafetyChart_Info_SeenBefore_Negative/Text") },
};
private static string unknown = "False".Localized("PW_SafetyChart_Info_Unknown/Text");


private double ChartScale = 10;
private Path[] paths = new Path[8];
private bool?[] checks = new bool?[8];
Expand All @@ -64,7 +79,6 @@ public sealed partial class PasswordSafetyChart : UserControl, INotifyPropertyCh
public bool SingleHitbox { get; set; } = false;
public event PropertyChangedEventHandler PropertyChanged;


public PasswordSafetyChart()
{
this.InitializeComponent();
Expand Down Expand Up @@ -155,7 +169,9 @@ public override string ToString()
StringBuilder sb = new StringBuilder();
for (int i = 0; i < checks.Length; i++)
{
sb.AppendLine(prefixes[i][ToIndex(checks[i])] + " " + messages[i].ToLower());
int index = ToIndex(checks[i]);
string suffix = index == 2 ? unknown : suffixes[i][index];
sb.AppendLine(infos[i] + " " + suffix);
}
return sb.ToString();
}
Expand Down
6 changes: 3 additions & 3 deletions EasePass/Dialogs/ChangePasswordDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ private void Dialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs
}
else if (changePWResult == ChangePasswordPageResult.IncorrectPassword)
{
InfoMessages.ChangePasswordWrong();
InfoMessages.ChangePasswordWrong(page.PasswordInfo);
}
else if (changePWResult == ChangePasswordPageResult.PWNotMatching)
{
InfoMessages.PasswordsDoNotMatch();
InfoMessages.PasswordsDoNotMatch(page.PasswordInfo);
}
else if (changePWResult == ChangePasswordPageResult.PWTooShort)
{
InfoMessages.PasswordTooShort();
InfoMessages.PasswordTooShort(page.PasswordInfo);
}
args.Cancel = true;
}
Expand Down
10 changes: 6 additions & 4 deletions EasePass/Dialogs/CreateDatabaseDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ copies or substantial portions of the Software.
using EasePass.Helper;
using EasePass.Models;
using EasePass.Views;
using Microsoft.UI.Xaml.Controls;
using System;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -37,12 +38,12 @@ public async Task<Database> ShowAsync()
XamlRoot = App.m_window.Content.XamlRoot,
};
page = new CreateDatabaseDialogPage();

dialog.Content = page;

dialog.Closing += Dialog_Closing;

var res = await dialog.ShowAsync();
if (res == Microsoft.UI.Xaml.Controls.ContentDialogResult.Primary)
if (res == ContentDialogResult.Primary)
{
var eval = page.Evaluate();
var path = Path.Combine(eval.path, eval.databaseName + ".epdb");
Expand All @@ -51,14 +52,15 @@ public async Task<Database> ShowAsync()
return null;
}

private void Dialog_Closing(Microsoft.UI.Xaml.Controls.ContentDialog sender, Microsoft.UI.Xaml.Controls.ContentDialogClosingEventArgs args)
private void Dialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
if (page == null)
if (page == null || args.Result != ContentDialogResult.Primary)
return;

//cancel on password mismatch:
if (!page.PasswordsMatch)
{
InfoMessages.PasswordsDoNotMatch(page.PasswordInfo);
args.Cancel = true;
}
}
Expand Down
32 changes: 25 additions & 7 deletions EasePass/Dialogs/InfoMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ copies or substantial portions of the Software.
using EasePass.Views;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Runtime.CompilerServices;

namespace EasePass.Dialogs
{
internal class InfoMessages
{
public static void CantDeleteDatabase() => new InfoBar().Show("Can't delete database!", "Create another database to delete this database!", InfoBarSeverity.Error, 5);
public static void CantDeleteLoadedDatabase() => new InfoBar().Show("Can't delete database!", "You can't delete a loaded database!", InfoBarSeverity.Error, 5);
public static void DatabaseDeleted() => new InfoBar().Show("Database deleted successfully!", "", InfoBarSeverity.Success, 5);
public static void DatabaseLoaded() => new InfoBar().Show("Database loaded successfully!", "", InfoBarSeverity.Success, 5);
public static void CantDeleteDatabase() => new InfoBar().Show("InfoMessages_DatabaseDeletionFailed", InfoBarSeverity.Error, 5);
public static void CantDeleteLoadedDatabase() => new InfoBar().Show("Can't delete Database!".Localized("InfoMessages_DatabaseDeletionFailed/Headline"), "You can't delete a loaded database!".Localized("InfoMessages_DatabaseDeleteLoaded/Text"), InfoBarSeverity.Error, 5);
public static void DatabaseDeleted() => new InfoBar().Show("InfoMessages_DatabaseDeleted", InfoBarSeverity.Success, 5);
public static void DatabaseLoaded() => new InfoBar().Show("InfoMessages_DatabaseLoaded", InfoBarSeverity.Success, 5);
public static void EnteredWrongPassword(int attempts) => new InfoBar().Show(
"Wrong password".Localized("InfoMessages_EnteredWrongPW/Headline"),
$"You entered the wrong password.\nPlease try again\n({attempts}/3)".Localized("InfoMessages_EnteredWrongPW/Text").Replace("{attempts}", attempts.ToString()),
Expand All @@ -53,6 +54,12 @@ internal class InfoMessages
"InfoMessages_PasswordTooShort",
InfoBarSeverity.Error
);
public static void PasswordTooShort(InfoBar infoBar) => infoBar.Show(
"InfoMessages_PasswordTooShort",
InfoBarSeverity.Error,
8,
false
);
public static void PasswordAlreadyUsed() => new InfoBar().Show(
"InfoMessages_PasswordAlreadyUsed",
InfoBarSeverity.Warning, 10
Expand All @@ -61,11 +68,22 @@ internal class InfoMessages
"InfoMessages_ChangePasswordWrong",
InfoBarSeverity.Error
);
public static void ChangePasswordWrong(InfoBar infoBar) => infoBar.Show(
"InfoMessages_ChangePasswordWrong",
InfoBarSeverity.Error,
8,
false
);
public static void PasswordsDoNotMatch() => new InfoBar().Show(
"Passwords do not match".Localized("InfoMessages_PasswordsDoNotMatch/Headline"),
"",
"InfoMessages_PasswordsDoNotMatch",
InfoBarSeverity.Error
);
public static void PasswordsDoNotMatch(InfoBar infoBar) => infoBar.Show(
"InfoMessages_PasswordsDoNotMatch",
InfoBarSeverity.Error,
8,
false
);
public static void SuccessfullyChangedPassword() => new InfoBar().Show(
"InfoMessages_SuccessfullyChangedPassword",
InfoBarSeverity.Success
Expand Down Expand Up @@ -138,7 +156,7 @@ internal class InfoMessages
InfoBarSeverity.Error, 10
);

public static void UnhandledException(Exception ex) => new InfoBar().Show("Unhandled Exception:", ex.Message, InfoBarSeverity.Error);
public static void UnhandledException(Exception ex) => new InfoBar().Show("Unhandled Exception:".Localized("InfoMessages_UnhandledException/Headline"), ex.Message, InfoBarSeverity.Error);
public static void NewVersionInfo(string version)
{
var btn = new Button { Content = "Changelog".Localized("InfoMessages_NewVersion/Content") };
Expand Down
28 changes: 18 additions & 10 deletions EasePass/Extensions/InfobarExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ public static void ShowUntilLogin(this InfoBar infobar, string title, string mes
{
ShowInfobar(infobar, title, message, null, severity, InfobarClearCondition.Login);
}
public static void Show(this InfoBar infobar, string localizationKey, InfoBarSeverity severity, int showSeconds = 8)
public static void Show(this InfoBar infobar, string localizationKey, InfoBarSeverity severity, int showSeconds = 8, bool showMainWindow = true)
{
Show(infobar, "".Localized(localizationKey + "/Headline"), "".Localized(localizationKey + "/Text"), null, severity, InfobarClearCondition.Timer, showSeconds);
Show(infobar, "".Localized(localizationKey + "/Headline"), "".Localized(localizationKey + "/Text"), null, severity, InfobarClearCondition.Timer, showSeconds, showMainWindow);
}
public static void Show(this InfoBar infobar, string title, string message, InfoBarSeverity severity, int showSeconds = 8)
public static void Show(this InfoBar infobar, string title, string message, InfoBarSeverity severity, int showSeconds = 8, bool showMainWindow = true)
{
Show(infobar, title, message, null, severity, InfobarClearCondition.Timer, showSeconds);
Show(infobar, title, message, null, severity, InfobarClearCondition.Timer, showSeconds, showMainWindow);
}
public static void Show(this InfoBar infobar, string title, string message, ButtonBase actionButton, InfoBarSeverity severity, InfobarClearCondition clearCondition = InfobarClearCondition.Timer, int showSeconds = 5)
public static void Show(this InfoBar infobar, string title, string message, ButtonBase actionButton, InfoBarSeverity severity, InfobarClearCondition clearCondition = InfobarClearCondition.Timer, int showSeconds = 5, bool showMainWindow = true)
{
ShowInfobar(infobar, title, message, actionButton, severity, clearCondition);
ShowInfobar(infobar, title, message, actionButton, severity, clearCondition, showMainWindow);

DispatcherTimer autoCloseTimer = new DispatcherTimer();
autoCloseTimer.Interval = new TimeSpan(0, 0, showSeconds);
Expand All @@ -62,7 +62,7 @@ public static void Show(this InfoBar infobar, string title, string message, Butt
};
}

private static void ShowInfobar(this InfoBar infobar, string title, string message, ButtonBase actionButton, InfoBarSeverity severity, InfobarClearCondition clearCondition)
private static void ShowInfobar(this InfoBar infobar, string title, string message, ButtonBase actionButton, InfoBarSeverity severity, InfobarClearCondition clearCondition, bool showMainWindow = true)
{
infobar.Title = title;
infobar.Message = message;
Expand All @@ -71,9 +71,13 @@ private static void ShowInfobar(this InfoBar infobar, string title, string messa
infobar.Tag = clearCondition;
infobar.IsOpen = true;
infobar.Background = Application.Current.Resources["SolidBackgroundFillColorBaseAltBrush"] as Brush;
MainWindow.InfoMessagesPanel.Children.Add(infobar);

if (showMainWindow)
{
MainWindow.InfoMessagesPanel.Children.Add(infobar);
}
}
public static void ShowInfobar(this InfoBar infobar, string title, string message, Control content, InfoBarSeverity severity)
public static void ShowInfobar(this InfoBar infobar, string title, string message, Control content, InfoBarSeverity severity, bool showMainWindow = true)
{
infobar.Title = title;
infobar.Message = message;
Expand All @@ -82,7 +86,11 @@ public static void ShowInfobar(this InfoBar infobar, string title, string messag
infobar.Tag = InfobarClearCondition.Manual;
infobar.IsOpen = true;
infobar.Background = Application.Current.Resources["SolidBackgroundFillColorBaseAltBrush"] as Brush;
MainWindow.InfoMessagesPanel.Children.Add(infobar);

if (showMainWindow)
{
MainWindow.InfoMessagesPanel.Children.Add(infobar);
}
}

public static void ClearInfobarsAfterLogin(StackPanel infobarDisplay)
Expand Down
Loading

0 comments on commit be53b9f

Please sign in to comment.