/*================================================================================================= * CONSTANTS *================================================================================================*/ /*PUBLIC******************************************************************************************/ /*PRIVATE*****************************************************************************************/ /*================================================================================================= * FIELDS *================================================================================================*/ /*PUBLIC******************************************************************************************/ /*PRIVATE*****************************************************************************************/ /*================================================================================================= * PROPERTIES *================================================================================================*/ /*PUBLIC******************************************************************************************/ /*PRIVATE*****************************************************************************************/ /*================================================================================================= * CONSTRUCTORS *================================================================================================*/ /*================================================================================================= * PUBLIC METHODS *================================================================================================*/ /*************************************************************************************************/ public static PasswordComplexityLevel checkEffectiveBitSize(int passSize, string pass) { int charSet = 0; PasswordComplexityLevel passStrength = PasswordComplexityLevel.Weak; charSet = getCharSetUsed(pass); double result = Math.Log(Math.Pow(charSet, passSize)) / Math.Log(2); if (result <= 32) { passStrength = PasswordComplexityLevel.Weak; } else if (result <= 64) { passStrength = PasswordComplexityLevel.Mediocre; } else if (result <= 128) { passStrength = PasswordComplexityLevel.Ok; } else if (result > 128) { passStrength = PasswordComplexityLevel.Great; } return(passStrength); }
/*************************************************************************************************/ public void DisplayPasswordComplexity(PasswordComplexityLevel complexity) { switch (complexity) { case PasswordComplexityLevel.Weak: createPasswordTextBox.ForeColor = Color.Red; break; case PasswordComplexityLevel.Mediocre: createPasswordTextBox.ForeColor = Color.Orange; break; case PasswordComplexityLevel.Ok: createPasswordTextBox.ForeColor = Color.YellowGreen; break; case PasswordComplexityLevel.Great: createPasswordTextBox.ForeColor = Color.Green; break; default: createPasswordTextBox.ForeColor = Color.FromArgb(242, 242, 242); break; } }
/*************************************************************************************************/ private void CalculatePasswordComplexity(string password) { PasswordComplexityLevel passwordComplexityLevel = PasswordComplexityLevel.Weak; passwordComplexityLevel = PasswordComplexity.checkEffectiveBitSize(password.Length, password); _loginView.DisplayPasswordComplexity(passwordComplexityLevel); }
/*================================================================================================= * PUBLIC METHODS *================================================================================================*/ /*************************************************************************************************/ /*================================================================================================= * PRIVATE METHODS *================================================================================================*/ /*************************************************************************************************/ private void PasswordTextChanged(string passwordText) { PasswordComplexityLevel passwordComplexityLevel = PasswordComplexityLevel.Weak; passwordComplexityLevel = PasswordComplexity.checkEffectiveBitSize(passwordText.Length, passwordText); _changePasswordView.DisplayPasswordComplexity(passwordComplexityLevel); }
/*************************************************************************************************/ public void DisplayPasswordComplexity(PasswordComplexityLevel complexity) { switch (complexity) { case PasswordComplexityLevel.Weak: passwordStrengthProgressBar.ForeColor = Color.Red; passwordStrengthProgressBar.BackColor = Color.Red; passwordStrengthProgressBar.Value = 25; passwordStrengthLabel.Text = "Weak"; break; case PasswordComplexityLevel.Mediocre: passwordStrengthProgressBar.ForeColor = Color.Orange; passwordStrengthProgressBar.BackColor = Color.Orange; passwordStrengthProgressBar.Value = 50; passwordStrengthLabel.Text = "Mediocre"; break; case PasswordComplexityLevel.Ok: passwordStrengthProgressBar.ForeColor = Color.YellowGreen; passwordStrengthProgressBar.BackColor = Color.YellowGreen; passwordStrengthProgressBar.Value = 75; passwordStrengthLabel.Text = "Ok"; break; case PasswordComplexityLevel.Great: passwordStrengthProgressBar.ForeColor = Color.Green; passwordStrengthProgressBar.BackColor = Color.Green; passwordStrengthProgressBar.Value = 100; passwordStrengthLabel.Text = "Great"; break; default: passwordStrengthProgressBar.ForeColor = Color.Red; passwordStrengthProgressBar.BackColor = Color.Red; passwordStrengthProgressBar.Value = 1; passwordStrengthLabel.Text = "Weak"; break; } }