diff --git a/src/App/Pages/LoginPage.cs b/src/App/Pages/LoginPage.cs index c1fdce5a2..9c9c0816c 100644 --- a/src/App/Pages/LoginPage.cs +++ b/src/App/Pages/LoginPage.cs @@ -61,7 +61,7 @@ namespace Bit.App.Pages entryKeyboard: Keyboard.Email, useLabelAsPlaceholder: true, imageSource: "envelope", containerPadding: padding); - var lastLoginEmail = _settings.GetValueOrDefault(Constants.LastLoginEmail); + var lastLoginEmail = _settings.GetValueOrDefault(Constants.LastLoginEmail, string.Empty); if(!string.IsNullOrWhiteSpace(_email)) { EmailCell.Entry.Text = _email; diff --git a/src/App/Pages/Settings/SettingsPage.cs b/src/App/Pages/Settings/SettingsPage.cs index ea07c12ea..743c0b37b 100644 --- a/src/App/Pages/Settings/SettingsPage.cs +++ b/src/App/Pages/Settings/SettingsPage.cs @@ -44,7 +44,7 @@ namespace Bit.App.Pages PinCell = new ExtendedSwitchCell { Text = "Unlock with PIN Code", - On = _settings.GetValueOrDefault(Constants.SettingPinUnlockOn) + On = _settings.GetValueOrDefault(Constants.SettingPinUnlockOn, false) }; PinCell.OnChanged += PinCell_Changed; @@ -76,7 +76,7 @@ namespace Bit.App.Pages FingerprintCell = new ExtendedSwitchCell { Text = "Unlock with " + fingerprintName, - On = _settings.GetValueOrDefault(Constants.SettingFingerprintUnlockOn), + On = _settings.GetValueOrDefault(Constants.SettingFingerprintUnlockOn, false), IsEnabled = _fingerprint.IsAvailable }; FingerprintCell.OnChanged += FingerprintCell_Changed; diff --git a/src/App/Pages/Settings/SettingsSyncPage.cs b/src/App/Pages/Settings/SettingsSyncPage.cs index a82b8fbd1..ade7865ff 100644 --- a/src/App/Pages/Settings/SettingsSyncPage.cs +++ b/src/App/Pages/Settings/SettingsSyncPage.cs @@ -72,7 +72,7 @@ namespace Bit.App.Pages private void SetLastSync() { - var lastSyncDate = _settings.GetValueOrDefault(Constants.LastSync); + var lastSyncDate = _settings.GetValueOrDefault(Constants.LastSync, null); try { LastSyncLabel.Text = "Last Sync: " + lastSyncDate?.ToLocalTime().ToString() ?? "Never"; diff --git a/src/App/Pages/Vault/VaultListSitesPage.cs b/src/App/Pages/Vault/VaultListSitesPage.cs index 49853ceaf..f2929411c 100644 --- a/src/App/Pages/Vault/VaultListSitesPage.cs +++ b/src/App/Pages/Vault/VaultListSitesPage.cs @@ -224,10 +224,10 @@ namespace Bit.App.Pages if(_connectivity.IsConnected && Device.OS == TargetPlatform.iOS && !_favorites) { - var pushPromptShow = _settings.GetValueOrDefault(Constants.PushInitialPromptShown); + var pushPromptShow = _settings.GetValueOrDefault(Constants.PushInitialPromptShown, false); Action registerAction = () => { - var lastPushRegistration = _settings.GetValueOrDefault(Constants.PushLastRegistrationDate); + var lastPushRegistration = _settings.GetValueOrDefault(Constants.PushLastRegistrationDate, null); if(!pushPromptShow || !lastPushRegistration.HasValue || (DateTime.UtcNow - lastPushRegistration) > TimeSpan.FromDays(1)) { diff --git a/src/App/Services/AuthService.cs b/src/App/Services/AuthService.cs index ebcffdf44..26887d020 100644 --- a/src/App/Services/AuthService.cs +++ b/src/App/Services/AuthService.cs @@ -76,12 +76,17 @@ namespace Bit.App.Services { get { - if(_userId != null) + if(!string.IsNullOrWhiteSpace(_userId)) { return _userId; } - _userId = _settings.GetValueOrDefault(UserIdKey); + var userId = _settings.GetValueOrDefault(UserIdKey, string.Empty); + if(!string.IsNullOrWhiteSpace(userId)) + { + _userId = userId; + } + return _userId; } set @@ -104,12 +109,17 @@ namespace Bit.App.Services { get { - if(_previousUserId != null) + if(!string.IsNullOrWhiteSpace(_previousUserId)) { return _previousUserId; } - _previousUserId = _settings.GetValueOrDefault(PreviousUserIdKey); + var previousUserId = _settings.GetValueOrDefault(PreviousUserIdKey, string.Empty); + if(!string.IsNullOrWhiteSpace(previousUserId)) + { + _previousUserId = previousUserId; + } + return _previousUserId; } private set @@ -128,12 +138,17 @@ namespace Bit.App.Services { get { - if(_email != null) + if(!string.IsNullOrWhiteSpace(_email)) { return _email; } - _email = _settings.GetValueOrDefault(EmailKey); + var email = _settings.GetValueOrDefault(EmailKey, string.Empty); + if(!string.IsNullOrWhiteSpace(email)) + { + _email = email; + } + return _email; } set @@ -155,14 +170,14 @@ namespace Bit.App.Services { get { - return _cryptoService.Key != null && Token != null && UserId != null; + return _cryptoService.Key != null && !string.IsNullOrWhiteSpace(Token) && !string.IsNullOrWhiteSpace(UserId); } } public bool IsAuthenticatedTwoFactor { get { - return _cryptoService.Key != null && Token != null && UserId == null; + return _cryptoService.Key != null && !string.IsNullOrWhiteSpace(Token) && string.IsNullOrWhiteSpace(UserId); } } diff --git a/src/App/Services/LockService.cs b/src/App/Services/LockService.cs index 92e463598..cef4dcea4 100644 --- a/src/App/Services/LockService.cs +++ b/src/App/Services/LockService.cs @@ -50,8 +50,8 @@ namespace Bit.App.Services } // What method are we using to unlock? - var fingerprintUnlock = _settings.GetValueOrDefault(Constants.SettingFingerprintUnlockOn); - var pinUnlock = _settings.GetValueOrDefault(Constants.SettingPinUnlockOn); + var fingerprintUnlock = _settings.GetValueOrDefault(Constants.SettingFingerprintUnlockOn, false); + var pinUnlock = _settings.GetValueOrDefault(Constants.SettingPinUnlockOn, false); if(fingerprintUnlock && _fingerprint.IsAvailable) { return LockType.Fingerprint; diff --git a/src/App/Services/SyncService.cs b/src/App/Services/SyncService.cs index b4b8766ce..bf2bfd2a3 100644 --- a/src/App/Services/SyncService.cs +++ b/src/App/Services/SyncService.cs @@ -170,7 +170,7 @@ namespace Bit.App.Services public async Task IncrementalSyncAsync(TimeSpan syncThreshold) { - DateTime? lastSync = _settings.GetValueOrDefault(Constants.LastSync); + DateTime? lastSync = _settings.GetValueOrDefault(Constants.LastSync, null); if(lastSync != null && DateTime.UtcNow - lastSync.Value < syncThreshold) { return false; @@ -187,7 +187,7 @@ namespace Bit.App.Services } var now = DateTime.UtcNow; - DateTime? lastSync = _settings.GetValueOrDefault(Constants.LastSync); + DateTime? lastSync = _settings.GetValueOrDefault(Constants.LastSync, null); if(lastSync == null) { return await FullSyncAsync().ConfigureAwait(false);