1using System.ComponentModel;
2using CommunityToolkit.Mvvm.ComponentModel;
3using CommunityToolkit.Mvvm.Input;
4using Microsoft.Maui.Controls.Shapes;
22 await base.OnInitialize();
32 await base.OnDispose();
41 this.UpdateToggleKeyboardText();
42 this.UpdateSecurityScore();
47 [NotifyCanExecuteChangedFor(nameof(ContinueCommand))]
48 private string? passwordText1;
53 [NotifyCanExecuteChangedFor(nameof(ContinueCommand))]
54 private string? passwordText2;
60 private bool isPasswordHidden =
true;
64 private double securityBar1Percentage;
67 private double securityBar2Percentage;
70 private double securityBar3Percentage;
76 private string securityText =
ServiceRef.
Localizer[nameof(AppResources.PasswordWeakSecurity)];
79 private string toggleNumericPasswordText =
ServiceRef.
Localizer[nameof(AppResources.OnboardingDefinePasswordCreateNumeric)];
82 private Keyboard keyboardType = Keyboard.Numeric;
85 private string toggleKeyboardTypeText =
ServiceRef.
Localizer[nameof(AppResources.OnboardingDefinePasswordCreateAlphanumeric)];
90 partial
void OnPasswordText1Changed(
string? value)
92 this.UpdateSecurityScore();
95 private void UpdateSecurityScore()
103 this.SecurityBar1Percentage = (Math.Min(Score, low) / low) * 100.0;
104 this.SecurityBar2Percentage = Math.Max((Math.Min(Score - low, medium - low) / (medium - low) * 100.0), 0);
105 this.SecurityBar3Percentage = Math.Max((Math.Min(Score - medium, high - medium) / (high - medium) * 100.0), 0);
112 else if (Score >= low)
125 private void TogglePasswordVisibility()
127 this.IsPasswordHidden = !this.IsPasswordHidden;
131 private void ValidatePassword()
155 if (
string.IsNullOrEmpty(this.PasswordText1))
156 return string.IsNullOrEmpty(this.PasswordText2);
158 return string.Equals(this.PasswordText1, this.PasswordText2, StringComparison.Ordinal);
195 PasswordStrength.ContainsAddress =>
ServiceRef.
Localizer[nameof(AppResources.PasswordContainsAddress)],
196 PasswordStrength.ContainsName =>
ServiceRef.
Localizer[nameof(AppResources.PasswordContainsName)],
197 PasswordStrength.ContainsPersonalNumber =>
ServiceRef.
Localizer[nameof(AppResources.PasswordContainsPersonalNumber)],
198 PasswordStrength.ContainsPhoneNumber =>
ServiceRef.
Localizer[nameof(AppResources.PasswordContainsPhoneNumber)],
199 PasswordStrength.ContainsEMail =>
ServiceRef.
Localizer[nameof(AppResources.PasswordContainsEMail)],
200 PasswordStrength.Strong =>
string.Empty,
201 _ =>
throw new NotImplementedException()
205 public bool CanContinue => this.PasswordStrength == PasswordStrength.Strong && this.
PasswordsMatch;
211 private void ToggleNumericPassword()
213 this.PasswordText1 =
string.Empty;
214 this.PasswordText2 =
string.Empty;
216 this.KeyboardType = this.KeyboardType == Keyboard.Numeric ? Keyboard.Default : Keyboard.Numeric;
218 this.UpdateToggleKeyboardText();
221 private void UpdateToggleKeyboardText()
223 if (this.KeyboardType == Keyboard.Default)
224 this.ToggleKeyboardTypeText =
ServiceRef.
Localizer[nameof(AppResources.OnboardingDefinePasswordCreateNumeric)];
226 this.ToggleKeyboardTypeText =
ServiceRef.
Localizer[nameof(AppResources.OnboardingDefinePasswordCreateAlphanumeric)];
230 [RelayCommand(CanExecute = nameof(CanContinue))]
231 private void Continue()
237 ServiceRef.TagProfile.LocalPassword = this.PasswordText1!;
238 if(
ServiceRef.PlatformSpecific.SupportsFingerprintAuthentication && isFirstPassword)
const int MaxPasswordIdenticalSymbols
Maximum number of identical symbols in a password.
const int MinPasswordLength
Minimum length for password
const int MinPasswordSymbolsFromDifferentClasses
Minimum number of symbols from at least two character classes (digits, letters, other) in a password.
const int MaxPasswordSequencedSymbols
Maximum number of sequenced symbols in a password.
const double MediumSecurityScoreThreshold
A password score value equal to or higher than this is considered medium security.
const double HighSecurityPasswordScoreThreshold
A password score value equal to or higher than this is considered high security.
const double MaxSecurityPasswordScoreThreshold
A password score value equal to or higher than this is considered to be of the highest security.
A set of never changing property constants and helpful values.
Base class that references services in the app.
static IUiService UiService
Service serializing and managing UI-related tasks.
static ITagProfile TagProfile
TAG Profile service.
static IStringLocalizer Localizer
Localization service
Static class that gives access to app-specific themed colors
static Color StrongPasswordForeground
Strong password foreground color.
static Color MediumPasswordForeground
Medium password foreground color.
static Color WeakPasswordForeground
Weak password foreground color.
Static class containing SVG Paths for symbols used in the app.
Geometry PasswordVisibilityPathData
Gets the path data for the password visibility icon depending if the password is hidden or not.
override async Task OnInitialize()
void LocalizationManagerEventHandler(object? sender, PropertyChangedEventArgs e)
EventHandler for localization change
static string GetLocalizedValidationError(PasswordStrength PasswordStrength)
Gets a localized error message, given a Password strength.
override async Task OnDispose()
bool IsPassword1NotValid
If First Password entry is not valid.
string LocalizedValidationError
Localized validation error message.
bool IsPassword2NotValid
If Second Password entry is not valid.
bool PasswordsMatch
Gets the value indicating whether the entered PasswordText1 is the same as the entered PasswordText2.
PasswordStrength ValidatePasswordStrength(string? Password)
Validates if the Password is strong enough.
DateTime? TestOtpTimestamp
Returns a timestamp if the user used a Test OTP Code.
string? LocalPasswordHash
A hashed version of the user's LocalPassword.
double CalculatePasswordScore(string? Password)
Returns a score for the password, which is based on the number of bits of security the password provi...
PasswordStrength
Represents a result of validating password strength.
RegistrationStep
The different steps of a TAG Profile registration journey.