mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +03:00
set pin from settings
This commit is contained in:
parent
c65b065dd7
commit
c5bd59e52c
9 changed files with 80 additions and 6 deletions
|
@ -10,6 +10,8 @@ using Android.OS;
|
||||||
using Android.Provider;
|
using Android.Provider;
|
||||||
using Android.Support.V4.App;
|
using Android.Support.V4.App;
|
||||||
using Android.Support.V4.Content;
|
using Android.Support.V4.Content;
|
||||||
|
using Android.Text;
|
||||||
|
using Android.Text.Method;
|
||||||
using Android.Webkit;
|
using Android.Webkit;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
using Bit.App.Abstractions;
|
using Bit.App.Abstractions;
|
||||||
|
@ -218,7 +220,8 @@ namespace Bit.Droid.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<string> DisplayPromptAync(string title = null, string description = null,
|
public Task<string> DisplayPromptAync(string title = null, string description = null,
|
||||||
string text = null, string okButtonText = null, string cancelButtonText = null)
|
string text = null, string okButtonText = null, string cancelButtonText = null,
|
||||||
|
bool numericKeyboard = false)
|
||||||
{
|
{
|
||||||
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
|
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
|
||||||
if(activity == null)
|
if(activity == null)
|
||||||
|
@ -231,12 +234,19 @@ namespace Bit.Droid.Services
|
||||||
alertBuilder.SetMessage(description);
|
alertBuilder.SetMessage(description);
|
||||||
var input = new EditText(activity)
|
var input = new EditText(activity)
|
||||||
{
|
{
|
||||||
InputType = Android.Text.InputTypes.ClassText
|
InputType = InputTypes.ClassText
|
||||||
};
|
};
|
||||||
if(text == null)
|
if(text == null)
|
||||||
{
|
{
|
||||||
text = string.Empty;
|
text = string.Empty;
|
||||||
}
|
}
|
||||||
|
if(numericKeyboard)
|
||||||
|
{
|
||||||
|
input.InputType = InputTypes.ClassNumber | InputTypes.NumberFlagDecimal | InputTypes.NumberFlagSigned;
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
|
input.KeyListener = DigitsKeyListener.GetInstance(false, false);
|
||||||
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
|
}
|
||||||
|
|
||||||
input.Text = text;
|
input.Text = text;
|
||||||
input.SetSelection(text.Length);
|
input.SetSelection(text.Length);
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Bit.App.Abstractions
|
||||||
Task ClearCacheAsync();
|
Task ClearCacheAsync();
|
||||||
Task SelectFileAsync();
|
Task SelectFileAsync();
|
||||||
Task<string> DisplayPromptAync(string title = null, string description = null, string text = null,
|
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();
|
void RateApp();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -44,6 +44,7 @@
|
||||||
x:Name="_pin"
|
x:Name="_pin"
|
||||||
Text="{Binding Pin}"
|
Text="{Binding Pin}"
|
||||||
StyleClass="box-value"
|
StyleClass="box-value"
|
||||||
|
Keyboard="Numeric"
|
||||||
IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
|
IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Grid.Column="0" />
|
Grid.Column="0" />
|
||||||
|
|
|
@ -102,7 +102,7 @@ namespace Bit.App.Pages
|
||||||
var decPin = await _cryptoService.DecryptToUtf8Async(new CipherString(protectedPin));
|
var decPin = await _cryptoService.DecryptToUtf8Async(new CipherString(protectedPin));
|
||||||
failed = decPin != Pin;
|
failed = decPin != Pin;
|
||||||
_lockService.PinLocked = failed;
|
_lockService.PinLocked = failed;
|
||||||
if(failed)
|
if(!failed)
|
||||||
{
|
{
|
||||||
DoContinue();
|
DoContinue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,10 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
await _vm.LockOptionsAsync();
|
await _vm.LockOptionsAsync();
|
||||||
}
|
}
|
||||||
|
else if(item.Name == AppResources.UnlockWithPIN)
|
||||||
|
{
|
||||||
|
await _vm.UpdatePinAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,48 @@ namespace Bit.App.Pages
|
||||||
BuildList();
|
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()
|
private void BuildList()
|
||||||
{
|
{
|
||||||
var doUpper = Device.RuntimePlatform != Device.Android;
|
var doUpper = Device.RuntimePlatform != Device.Android;
|
||||||
|
@ -202,7 +244,7 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
new SettingsPageListItem { Name = AppResources.LockOptions, SubLabel = _lockOptionValue },
|
new SettingsPageListItem { Name = AppResources.LockOptions, SubLabel = _lockOptionValue },
|
||||||
new SettingsPageListItem { Name = string.Format(AppResources.UnlockWith, AppResources.Fingerprint) },
|
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.LockNow },
|
||||||
new SettingsPageListItem { Name = AppResources.TwoStepLogin }
|
new SettingsPageListItem { Name = AppResources.TwoStepLogin }
|
||||||
};
|
};
|
||||||
|
|
9
src/App/Resources/AppResources.Designer.cs
generated
9
src/App/Resources/AppResources.Designer.cs
generated
|
@ -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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Enter a 4 digit PIN code to unlock the app with..
|
/// Looks up a localized string similar to Enter a 4 digit PIN code to unlock the app with..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1496,4 +1496,7 @@
|
||||||
<data name="LockOption5Minutes" xml:space="preserve">
|
<data name="LockOption5Minutes" xml:space="preserve">
|
||||||
<value>5 minutes</value>
|
<value>5 minutes</value>
|
||||||
</data>
|
</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>
|
</root>
|
|
@ -173,7 +173,8 @@ namespace Bit.iOS.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<string> DisplayPromptAync(string title = null, string description = null,
|
public Task<string> DisplayPromptAync(string title = null, string description = null,
|
||||||
string text = null, string okButtonText = null, string cancelButtonText = null)
|
string text = null, string okButtonText = null, string cancelButtonText = null,
|
||||||
|
bool numericKeyboard = false)
|
||||||
{
|
{
|
||||||
var result = new TaskCompletionSource<string>();
|
var result = new TaskCompletionSource<string>();
|
||||||
var alert = UIAlertController.Create(title ?? string.Empty, description, UIAlertControllerStyle.Alert);
|
var alert = UIAlertController.Create(title ?? string.Empty, description, UIAlertControllerStyle.Alert);
|
||||||
|
@ -192,6 +193,10 @@ namespace Bit.iOS.Services
|
||||||
{
|
{
|
||||||
input = x;
|
input = x;
|
||||||
input.Text = text ?? string.Empty;
|
input.Text = text ?? string.Empty;
|
||||||
|
if(numericKeyboard)
|
||||||
|
{
|
||||||
|
input.KeyboardType = UIKeyboardType.NumberPad;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var vc = GetPresentedViewController();
|
var vc = GetPresentedViewController();
|
||||||
vc?.PresentViewController(alert, true, null);
|
vc?.PresentViewController(alert, true, null);
|
||||||
|
|
Loading…
Reference in a new issue