mirror of
https://github.com/bitwarden/mobile
synced 2025-12-20 10:13:42 +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:
46
src/App/Services/MobilePasswordRepromptService.cs
Normal file
46
src/App/Services/MobilePasswordRepromptService.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Resources;
|
||||
using System;
|
||||
|
||||
namespace Bit.App.Services
|
||||
{
|
||||
public class MobilePasswordRepromptService : IPasswordRepromptService
|
||||
{
|
||||
private readonly IPlatformUtilsService _platformUtilsService;
|
||||
private readonly ICryptoService _cryptoService;
|
||||
|
||||
public MobilePasswordRepromptService(IPlatformUtilsService platformUtilsService, ICryptoService cryptoService)
|
||||
{
|
||||
_platformUtilsService = platformUtilsService;
|
||||
_cryptoService = cryptoService;
|
||||
}
|
||||
|
||||
public string[] ProtectedFields { get; } = { "LoginTotp", "LoginPassword", "H_FieldValue", "CardNumber", "CardCode" };
|
||||
|
||||
public async Task<bool> ShowPasswordPromptAsync()
|
||||
{
|
||||
Func<string, Task<bool>> validator = async (string password) =>
|
||||
{
|
||||
// Assume user has canceled.
|
||||
if (string.IsNullOrWhiteSpace(password))
|
||||
{
|
||||
return false;
|
||||
};
|
||||
|
||||
var keyHash = await _cryptoService.HashPasswordAsync(password, null);
|
||||
var storedKeyHash = await _cryptoService.GetKeyHashAsync();
|
||||
|
||||
if (storedKeyHash == null || keyHash == null || storedKeyHash != keyHash)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
return await _platformUtilsService.ShowPasswordDialogAsync(AppResources.PasswordConfirmation, AppResources.PasswordConfirmationDesc, validator);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user