mirror of
https://github.com/bitwarden/mobile
synced 2025-12-19 01:33:22 +00:00
Password reprompt (#1365)
* Make card number hidden * Add support for password reprompt * Rename PasswordPrompt to Reprompt * Protect autofill * Use Enums.CipherRepromptType * Fix iOS not building * Protect iOS autofill * Update to match jslib * Fix failing build
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Bit.App.Resources;
|
||||
using Bit.App.Utilities;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.View;
|
||||
using Bit.Core.Utilities;
|
||||
@@ -23,10 +24,12 @@ namespace Bit.App.Pages
|
||||
private readonly IAuditService _auditService;
|
||||
private readonly IMessagingService _messagingService;
|
||||
private readonly IEventService _eventService;
|
||||
private readonly IPasswordRepromptService _passwordRepromptService;
|
||||
private CipherView _cipher;
|
||||
private List<ViewPageFieldViewModel> _fields;
|
||||
private bool _canAccessPremium;
|
||||
private bool _showPassword;
|
||||
private bool _showCardNumber;
|
||||
private bool _showCardCode;
|
||||
private string _totpCode;
|
||||
private string _totpCodeFormatted;
|
||||
@@ -36,6 +39,7 @@ namespace Bit.App.Pages
|
||||
private string _previousCipherId;
|
||||
private byte[] _attachmentData;
|
||||
private string _attachmentFilename;
|
||||
private bool _passwordReprompted;
|
||||
|
||||
public ViewPageViewModel()
|
||||
{
|
||||
@@ -47,11 +51,13 @@ namespace Bit.App.Pages
|
||||
_auditService = ServiceContainer.Resolve<IAuditService>("auditService");
|
||||
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
||||
_eventService = ServiceContainer.Resolve<IEventService>("eventService");
|
||||
_passwordRepromptService = ServiceContainer.Resolve<IPasswordRepromptService>("passwordRepromptService");
|
||||
CopyCommand = new Command<string>((id) => CopyAsync(id, null));
|
||||
CopyUriCommand = new Command<LoginUriView>(CopyUri);
|
||||
CopyFieldCommand = new Command<FieldView>(CopyField);
|
||||
LaunchUriCommand = new Command<LoginUriView>(LaunchUri);
|
||||
TogglePasswordCommand = new Command(TogglePassword);
|
||||
ToggleCardNumberCommand = new Command(ToggleCardNumber);
|
||||
ToggleCardCodeCommand = new Command(ToggleCardCode);
|
||||
CheckPasswordCommand = new Command(CheckPasswordAsync);
|
||||
DownloadAttachmentCommand = new Command<AttachmentView>(DownloadAttachmentAsync);
|
||||
@@ -64,6 +70,7 @@ namespace Bit.App.Pages
|
||||
public Command CopyFieldCommand { get; set; }
|
||||
public Command LaunchUriCommand { get; set; }
|
||||
public Command TogglePasswordCommand { get; set; }
|
||||
public Command ToggleCardNumberCommand { get; set; }
|
||||
public Command ToggleCardCodeCommand { get; set; }
|
||||
public Command CheckPasswordCommand { get; set; }
|
||||
public Command DownloadAttachmentCommand { get; set; }
|
||||
@@ -109,6 +116,15 @@ namespace Bit.App.Pages
|
||||
nameof(ShowPasswordIcon)
|
||||
});
|
||||
}
|
||||
public bool ShowCardNumber
|
||||
{
|
||||
get => _showCardNumber;
|
||||
set => SetProperty(ref _showCardNumber, value,
|
||||
additionalPropertyNames: new string[]
|
||||
{
|
||||
nameof(ShowCardNumberIcon)
|
||||
});
|
||||
}
|
||||
public bool ShowCardCode
|
||||
{
|
||||
get => _showCardCode;
|
||||
@@ -188,6 +204,7 @@ namespace Bit.App.Pages
|
||||
public bool ShowTotp => IsLogin && !string.IsNullOrWhiteSpace(Cipher.Login.Totp) &&
|
||||
!string.IsNullOrWhiteSpace(TotpCodeFormatted);
|
||||
public string ShowPasswordIcon => ShowPassword ? "" : "";
|
||||
public string ShowCardNumberIcon => ShowCardNumber ? "" : "";
|
||||
public string ShowCardCodeIcon => ShowCardCode ? "" : "";
|
||||
public string TotpCodeFormatted
|
||||
{
|
||||
@@ -226,7 +243,7 @@ namespace Bit.App.Pages
|
||||
}
|
||||
Cipher = await cipher.DecryptAsync();
|
||||
CanAccessPremium = await _userService.CanAccessPremiumAsync();
|
||||
Fields = Cipher.Fields?.Select(f => new ViewPageFieldViewModel(Cipher, f)).ToList();
|
||||
Fields = Cipher.Fields?.Select(f => new ViewPageFieldViewModel(this, Cipher, f)).ToList();
|
||||
|
||||
if (Cipher.Type == Core.Enums.CipherType.Login && !string.IsNullOrWhiteSpace(Cipher.Login.Totp) &&
|
||||
(Cipher.OrganizationUseTotp || CanAccessPremium))
|
||||
@@ -259,8 +276,13 @@ namespace Bit.App.Pages
|
||||
_totpInterval = null;
|
||||
}
|
||||
|
||||
public void TogglePassword()
|
||||
public async void TogglePassword()
|
||||
{
|
||||
if (! await PromptPasswordAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ShowPassword = !ShowPassword;
|
||||
if (ShowPassword)
|
||||
{
|
||||
@@ -268,8 +290,26 @@ namespace Bit.App.Pages
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleCardCode()
|
||||
public async void ToggleCardNumber()
|
||||
{
|
||||
if (!await PromptPasswordAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShowCardNumber = !ShowCardNumber;
|
||||
if (ShowCardNumber)
|
||||
{
|
||||
var task = _eventService.CollectAsync(
|
||||
Core.Enums.EventType.Cipher_ClientToggledCardNumberVisible, CipherId);
|
||||
}
|
||||
}
|
||||
|
||||
public async void ToggleCardCode()
|
||||
{
|
||||
if (!await PromptPasswordAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShowCardCode = !ShowCardCode;
|
||||
if (ShowCardCode)
|
||||
{
|
||||
@@ -564,6 +604,11 @@ namespace Bit.App.Pages
|
||||
|
||||
private async void CopyAsync(string id, string text = null)
|
||||
{
|
||||
if (_passwordRepromptService.ProtectedFields.Contains(id) && !await PromptPasswordAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string name = null;
|
||||
if (id == "LoginUsername")
|
||||
{
|
||||
@@ -638,16 +683,28 @@ namespace Bit.App.Pages
|
||||
_platformUtilsService.LaunchUri(uri.LaunchUri);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task<bool> PromptPasswordAsync()
|
||||
{
|
||||
if (Cipher.Reprompt == CipherRepromptType.None || _passwordReprompted)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return _passwordReprompted = await _passwordRepromptService.ShowPasswordPromptAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public class ViewPageFieldViewModel : ExtendedViewModel
|
||||
{
|
||||
private ViewPageViewModel _vm;
|
||||
private FieldView _field;
|
||||
private CipherView _cipher;
|
||||
private bool _showHiddenValue;
|
||||
|
||||
public ViewPageFieldViewModel(CipherView cipher, FieldView field)
|
||||
public ViewPageFieldViewModel(ViewPageViewModel vm, CipherView cipher, FieldView field)
|
||||
{
|
||||
_vm = vm;
|
||||
_cipher = cipher;
|
||||
Field = field;
|
||||
ToggleHiddenValueCommand = new Command(ToggleHiddenValue);
|
||||
@@ -688,8 +745,12 @@ namespace Bit.App.Pages
|
||||
public bool ShowCopyButton => _field.Type != Core.Enums.FieldType.Boolean &&
|
||||
!string.IsNullOrWhiteSpace(_field.Value) && !(IsHiddenType && !_cipher.ViewPassword);
|
||||
|
||||
public void ToggleHiddenValue()
|
||||
public async void ToggleHiddenValue()
|
||||
{
|
||||
if (!await _vm.PromptPasswordAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShowHiddenValue = !ShowHiddenValue;
|
||||
if (ShowHiddenValue)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user