1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-06 10:34:07 +00:00

set pin from settings

This commit is contained in:
Kyle Spearrin
2019-05-16 15:54:21 -04:00
parent c65b065dd7
commit c5bd59e52c
9 changed files with 80 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ namespace Bit.App.Abstractions
Task ClearCacheAsync();
Task SelectFileAsync();
Task<string> DisplayPromptAync(string title = null, string description = null, string text = null,
string okButtonText = null, string cancelButtonText = null);
string okButtonText = null, string cancelButtonText = null, bool numericKeyboard = false);
void RateApp();
}
}

View File

@@ -44,6 +44,7 @@
x:Name="_pin"
Text="{Binding Pin}"
StyleClass="box-value"
Keyboard="Numeric"
IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
Grid.Row="1"
Grid.Column="0" />

View File

@@ -102,7 +102,7 @@ namespace Bit.App.Pages
var decPin = await _cryptoService.DecryptToUtf8Async(new CipherString(protectedPin));
failed = decPin != Pin;
_lockService.PinLocked = failed;
if(failed)
if(!failed)
{
DoContinue();
}

View File

@@ -98,6 +98,10 @@ namespace Bit.App.Pages
{
await _vm.LockOptionsAsync();
}
else if(item.Name == AppResources.UnlockWithPIN)
{
await _vm.UpdatePinAsync();
}
}
}
}

View File

@@ -190,6 +190,48 @@ namespace Bit.App.Pages
BuildList();
}
public async Task UpdatePinAsync()
{
_pin = !_pin;
if(_pin)
{
var pin = await _deviceActionService.DisplayPromptAync(AppResources.EnterPIN,
AppResources.SetPINDescription, null, AppResources.Submit, AppResources.Cancel, true);
var masterPassOnRestart = true;
if(!string.IsNullOrWhiteSpace(pin))
{
if(masterPassOnRestart)
{
var encPin = await _cryptoService.EncryptAsync(pin);
await _storageService.SaveAsync(Constants.ProtectedPin, encPin.EncryptedString);
}
else
{
var kdf = await _userService.GetKdfAsync();
var kdfIterations = await _userService.GetKdfIterationsAsync();
var email = await _userService.GetEmailAsync();
var pinKey = await _cryptoService.MakePinKeyAysnc(pin, email,
kdf.GetValueOrDefault(Core.Enums.KdfType.PBKDF2_SHA256),
kdfIterations.GetValueOrDefault(5000));
var key = await _cryptoService.GetKeyAsync();
var pinProtectedKey = await _cryptoService.EncryptAsync(key.Key, pinKey);
await _storageService.SaveAsync(Constants.PinProtectedKey, pinProtectedKey.EncryptedString);
}
}
else
{
_pin = false;
}
}
if(!_pin)
{
await _storageService.RemoveAsync(Constants.PinProtectedKey);
await _storageService.RemoveAsync(Constants.ProtectedPin);
}
BuildList();
}
private void BuildList()
{
var doUpper = Device.RuntimePlatform != Device.Android;
@@ -202,7 +244,7 @@ namespace Bit.App.Pages
{
new SettingsPageListItem { Name = AppResources.LockOptions, SubLabel = _lockOptionValue },
new SettingsPageListItem { Name = string.Format(AppResources.UnlockWith, AppResources.Fingerprint) },
new SettingsPageListItem { Name = AppResources.UnlockWithPIN },
new SettingsPageListItem { Name = AppResources.UnlockWithPIN, SubLabel = _pin ? "✓" : null },
new SettingsPageListItem { Name = AppResources.LockNow },
new SettingsPageListItem { Name = AppResources.TwoStepLogin }
};

View File

@@ -3183,6 +3183,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Set your PIN code for unlocking Bitwarden. Your PIN settings will be reset if you ever fully log out of the application..
/// </summary>
public static string SetPINDescription {
get {
return ResourceManager.GetString("SetPINDescription", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enter a 4 digit PIN code to unlock the app with..
/// </summary>

View File

@@ -1496,4 +1496,7 @@
<data name="LockOption5Minutes" xml:space="preserve">
<value>5 minutes</value>
</data>
<data name="SetPINDescription" xml:space="preserve">
<value>Set your PIN code for unlocking Bitwarden. Your PIN settings will be reset if you ever fully log out of the application.</value>
</data>
</root>