1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-15 07:43:37 +00:00

PS-591 Fix avoid ambiguous characters #1664 (#1906)

* PS-591 - iOS - Avoid ambiguous characters is activated inside the main client, but is deactivated when creating a vault item from the autofill prompt. #1664
- Refactor the name of the property Ambiguous to AvoidAmbiguous, this naming was misleading.
- Fixed bug where the boolean value for the AvoidAmbiguous property was being stored inverted.

* PS-591 - iOS - Avoid ambiguous characters is activated inside the main client, but is deactivated when creating a vault item from the autofill prompt. #1664
- Changed AvoidAmbiguous to AllowAmbiguous
- Added wrapper Prop to bind UI Toggle to VM

Co-authored-by: André Bispo <abispo@bitwarden.com>
This commit is contained in:
André Filipe da Silva Bispo
2022-05-18 14:58:49 +01:00
committed by GitHub
parent 604e3b6892
commit bcbc2738ca
5 changed files with 26 additions and 16 deletions

View File

@@ -277,7 +277,7 @@
StyleClass="box-label-regular" StyleClass="box-label-regular"
HorizontalOptions="StartAndExpand" /> HorizontalOptions="StartAndExpand" />
<Switch <Switch
IsToggled="{Binding AvoidAmbiguous}" IsToggled="{Binding AvoidAmbiguousChars}"
StyleClass="box-value" StyleClass="box-value"
HorizontalOptions="End" /> HorizontalOptions="End" />
</StackLayout> </StackLayout>

View File

@@ -23,7 +23,7 @@ namespace Bit.App.Pages
private bool _lowercase; private bool _lowercase;
private bool _number; private bool _number;
private bool _special; private bool _special;
private bool _avoidAmbiguous; private bool _allowAmbiguousChars;
private int _minNumber; private int _minNumber;
private int _minSpecial; private int _minSpecial;
private int _length = 5; private int _length = 5;
@@ -130,19 +130,29 @@ namespace Bit.App.Pages
} }
} }
public bool AvoidAmbiguous public bool AllowAmbiguousChars
{ {
get => _avoidAmbiguous; get => _allowAmbiguousChars;
set set
{ {
if (SetProperty(ref _avoidAmbiguous, value)) if (SetProperty(ref _allowAmbiguousChars, value,
additionalPropertyNames: new string[]
{
nameof(AvoidAmbiguousChars)
}))
{ {
_options.Ambiguous = !value; _options.AllowAmbiguousChar = value;
var task = SaveOptionsAsync(); var task = SaveOptionsAsync();
} }
} }
} }
public bool AvoidAmbiguousChars
{
get => !AllowAmbiguousChars;
set => AllowAmbiguousChars = !value;
}
public int MinNumber public int MinNumber
{ {
get => _minNumber; get => _minNumber;
@@ -315,7 +325,7 @@ namespace Bit.App.Pages
private void LoadFromOptions() private void LoadFromOptions()
{ {
AvoidAmbiguous = !_options.Ambiguous.GetValueOrDefault(); AllowAmbiguousChars = _options.AllowAmbiguousChar.GetValueOrDefault();
TypeSelectedIndex = _options.Type == "passphrase" ? 1 : 0; TypeSelectedIndex = _options.Type == "passphrase" ? 1 : 0;
IsPassword = TypeSelectedIndex == 0; IsPassword = TypeSelectedIndex == 0;
MinNumber = _options.MinNumber.GetValueOrDefault(); MinNumber = _options.MinNumber.GetValueOrDefault();
@@ -333,7 +343,7 @@ namespace Bit.App.Pages
private void SetOptions() private void SetOptions()
{ {
_options.Ambiguous = !AvoidAmbiguous; _options.AllowAmbiguousChar = AllowAmbiguousChars;
_options.Type = TypeSelectedIndex == 1 ? "passphrase" : "password"; _options.Type = TypeSelectedIndex == 1 ? "passphrase" : "password";
_options.MinNumber = MinNumber; _options.MinNumber = MinNumber;
_options.MinSpecial = MinSpecial; _options.MinSpecial = MinSpecial;

View File

@@ -9,7 +9,7 @@
if (defaultOptions) if (defaultOptions)
{ {
Length = 14; Length = 14;
Ambiguous = false; AllowAmbiguousChar = true;
Number = true; Number = true;
MinNumber = 1; MinNumber = 1;
Uppercase = true; Uppercase = true;
@@ -27,7 +27,7 @@
} }
public int? Length { get; set; } public int? Length { get; set; }
public bool? Ambiguous { get; set; } public bool? AllowAmbiguousChar { get; set; }
public bool? Number { get; set; } public bool? Number { get; set; }
public int? MinNumber { get; set; } public int? MinNumber { get; set; }
public bool? Uppercase { get; set; } public bool? Uppercase { get; set; }
@@ -45,7 +45,7 @@
public void Merge(PasswordGenerationOptions defaults) public void Merge(PasswordGenerationOptions defaults)
{ {
Length = Length ?? defaults.Length; Length = Length ?? defaults.Length;
Ambiguous = Ambiguous ?? defaults.Ambiguous; AllowAmbiguousChar = AllowAmbiguousChar ?? defaults.AllowAmbiguousChar;
Number = Number ?? defaults.Number; Number = Number ?? defaults.Number;
MinNumber = MinNumber ?? defaults.MinNumber; MinNumber = MinNumber ?? defaults.MinNumber;
Uppercase = Uppercase ?? defaults.Uppercase; Uppercase = Uppercase ?? defaults.Uppercase;

View File

@@ -93,7 +93,7 @@ namespace Bit.Core.Services
// Build out other character sets // Build out other character sets
var allCharSet = string.Empty; var allCharSet = string.Empty;
var lowercaseCharSet = LowercaseCharSet; var lowercaseCharSet = LowercaseCharSet;
if (options.Ambiguous.GetValueOrDefault()) if (options.AllowAmbiguousChar.GetValueOrDefault())
{ {
lowercaseCharSet = string.Concat(lowercaseCharSet, "l"); lowercaseCharSet = string.Concat(lowercaseCharSet, "l");
} }
@@ -103,7 +103,7 @@ namespace Bit.Core.Services
} }
var uppercaseCharSet = UppercaseCharSet; var uppercaseCharSet = UppercaseCharSet;
if (options.Ambiguous.GetValueOrDefault()) if (options.AllowAmbiguousChar.GetValueOrDefault())
{ {
uppercaseCharSet = string.Concat(uppercaseCharSet, "IO"); uppercaseCharSet = string.Concat(uppercaseCharSet, "IO");
} }
@@ -113,7 +113,7 @@ namespace Bit.Core.Services
} }
var numberCharSet = NumberCharSet; var numberCharSet = NumberCharSet;
if (options.Ambiguous.GetValueOrDefault()) if (options.AllowAmbiguousChar.GetValueOrDefault())
{ {
numberCharSet = string.Concat(numberCharSet, "01"); numberCharSet = string.Concat(numberCharSet, "01");
} }

View File

@@ -101,7 +101,7 @@ namespace Bit.iOS.Core.Controllers
MinNumbersCell.Value = options.MinNumber.GetValueOrDefault(1); MinNumbersCell.Value = options.MinNumber.GetValueOrDefault(1);
MinSpecialCell.Value = options.MinSpecial.GetValueOrDefault(1); MinSpecialCell.Value = options.MinSpecial.GetValueOrDefault(1);
LengthCell.Value = options.Length.GetValueOrDefault(14); LengthCell.Value = options.Length.GetValueOrDefault(14);
AmbiguousCell.Switch.On = options.Ambiguous.GetValueOrDefault(); AmbiguousCell.Switch.On = !options.AllowAmbiguousChar.GetValueOrDefault();
NumWordsCell.Value = options.NumWords.GetValueOrDefault(3); NumWordsCell.Value = options.NumWords.GetValueOrDefault(3);
WordSeparatorCell.TextField.Text = options.WordSeparator ?? ""; WordSeparatorCell.TextField.Text = options.WordSeparator ?? "";
@@ -219,7 +219,7 @@ namespace Bit.iOS.Core.Controllers
Special = SpecialCell.Switch.On, Special = SpecialCell.Switch.On,
MinSpecial = MinSpecialCell.Value, MinSpecial = MinSpecialCell.Value,
MinNumber = MinNumbersCell.Value, MinNumber = MinNumbersCell.Value,
Ambiguous = AmbiguousCell.Switch.On, AllowAmbiguousChar = !AmbiguousCell.Switch.On,
NumWords = NumWordsCell.Value, NumWords = NumWordsCell.Value,
WordSeparator = WordSeparatorCell.TextField.Text, WordSeparator = WordSeparatorCell.TextField.Text,
Capitalize = CapitalizeCell.Switch.On, Capitalize = CapitalizeCell.Switch.On,