mirror of
https://github.com/bitwarden/mobile
synced 2025-12-21 02:33:36 +00:00
[SG-460] Master Password security checks (mobile) (#2312)
* [SG-886] MasterPassword Strength Indicator (#2238) * [SG-886] Add password strength indicator control * [SG-570] Add weak password dialog check * [SG-886] rename enum password strength * [SG-886] Change control scale * [SG-886] Move calculate user inputs to IPasswordGenerationService, refactor. * [SG-886] Move formatted string to xaml. Move minimum chars to constant * [SG-886] String to enum converter * [SG-886] PR fixes. Code refactor control * [SG-886] Update UI on OS theme change. * [SG-886] Move colors to view * [SG-886] Fixed password strength validation * [SG-564][SG-565] Check Exposed Password (#2239) * [SG-886] Add password strength indicator control * [SG-570] Add weak password dialog check * [SG-886] rename enum password strength * [SG-564] [SG-565] Add check for exposed password and show dialog * code format * [SG-886] Change control scale * [SG-886] Move calculate user inputs to IPasswordGenerationService, refactor. * [SG-886] Move formatted string to xaml. Move minimum chars to constant * [SG-886] String to enum converter * [SG-886] Remove import * [SG-886] Update UI on OS theme change. * [SG-886] Move colors to view * [SG-886] Fixed password strength validation
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Utilities;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class PasswordStrengthViewModel : ExtendedViewModel
|
||||
{
|
||||
private readonly IPasswordGenerationService _passwordGenerationService;
|
||||
private readonly IPasswordStrengthable _passwordStrengthable;
|
||||
private double _passwordStrength;
|
||||
private Color _passwordColor;
|
||||
private PasswordStrengthLevel? _passwordStrengthLevel;
|
||||
|
||||
public PasswordStrengthViewModel(IPasswordStrengthable passwordStrengthable)
|
||||
{
|
||||
_passwordGenerationService = ServiceContainer.Resolve<IPasswordGenerationService>();
|
||||
_passwordStrengthable = passwordStrengthable;
|
||||
}
|
||||
|
||||
public double PasswordStrength
|
||||
{
|
||||
get => _passwordStrength;
|
||||
set => SetProperty(ref _passwordStrength, value);
|
||||
}
|
||||
|
||||
public PasswordStrengthLevel? PasswordStrengthLevel
|
||||
{
|
||||
get => _passwordStrengthLevel;
|
||||
set => SetProperty(ref _passwordStrengthLevel, value);
|
||||
}
|
||||
|
||||
public List<string> GetPasswordStrengthUserInput(string email) => _passwordGenerationService.GetPasswordStrengthUserInput(email);
|
||||
|
||||
public void CalculatePasswordStrength()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_passwordStrengthable.Password))
|
||||
{
|
||||
PasswordStrength = 0;
|
||||
PasswordStrengthLevel = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var passwordStrength = _passwordGenerationService.PasswordStrength(_passwordStrengthable.Password, _passwordStrengthable.UserInputs);
|
||||
// The passwordStrength.Score is 0..4, convertion was made to be used as a progress directly by the control 0..1
|
||||
PasswordStrength = (passwordStrength.Score + 1f) / 5f;
|
||||
if (PasswordStrength <= 0.4f)
|
||||
{
|
||||
PasswordStrengthLevel = Controls.PasswordStrengthLevel.VeryWeak;
|
||||
}
|
||||
else if (PasswordStrength <= 0.6f)
|
||||
{
|
||||
PasswordStrengthLevel = Controls.PasswordStrengthLevel.Weak;
|
||||
}
|
||||
else if (PasswordStrength <= 0.8f)
|
||||
{
|
||||
PasswordStrengthLevel = Controls.PasswordStrengthLevel.Good;
|
||||
}
|
||||
else
|
||||
{
|
||||
PasswordStrengthLevel = Controls.PasswordStrengthLevel.Strong;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user