public void PersistPincode(MobilePolicy policy)
        {
            DeletePincode();
            var newPin = new PasswordCredential(PasswordVaultSecuredData, PasswordVaultPincode,
                                                JsonConvert.SerializeObject(policy));

            _vault.Add(newPin);
            PlatformAdapter.SendToCustomLogger("AuthStorageHelper.PersistPincode - pincode added to vault",
                                               LoggingLevel.Verbose);
        }
        public void PersistPincode(MobilePolicy policy)
        {
            DeletePincode();
            var newPin = new PasswordCredential(PasswordVaultSecuredData, PasswordVaultPincode,
                                                JsonConvert.SerializeObject(policy));

            _vault.Add(newPin);
            LoggingService.Log("pincode added to vault",
                               LoggingLevel.Verbose);
        }
        /// <summary>
        ///     This method will launch the pincode screen if the policy requires it.
        ///     If determined that no pincode screen is required, the flag requiring the pincode will be cleared.
        /// </summary>
        public static async void LaunchPincodeScreen()
        {
            var frame = Window.Current.Content as Frame;

            if (frame != null && typeof(PincodeDialog) != frame.SourcePageType)
            {
                await frame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    SDKServiceLocator.Get <ILoggingService>().Log(" Launching Pincode Screen", LoggingLevel.Information);
                    Account account = AccountManager.GetAccount();
                    if (account != null)
                    {
                        PincodeOptions options = null;
                        bool required          = AuthStorageHelper.IsPincodeRequired();
                        if (account.Policy != null && !IsPincodeSet())
                        {
                            options = new PincodeOptions(PincodeOptions.PincodeScreen.Create, account, "");
                        }
                        else if (required)
                        {
                            MobilePolicy policy = AuthStorageHelper.GetMobilePolicy();
                            if (account.Policy != null)
                            {
                                if (policy.ScreenLockTimeout < account.Policy.ScreenLockTimeout)
                                {
                                    policy.ScreenLockTimeout = account.Policy.ScreenLockTimeout;
                                    AuthStorageHelper.GetAuthStorageHelper().PersistPincode(policy);
                                }
                                if (policy.PinLength < account.Policy.PinLength)
                                {
                                    options = new PincodeOptions(PincodeOptions.PincodeScreen.Create, account, "");
                                }
                                else
                                {
                                    options = new PincodeOptions(PincodeOptions.PincodeScreen.Locked, account, "");
                                }
                            }
                            else
                            {
                                options = new PincodeOptions(PincodeOptions.PincodeScreen.Locked, account, "");
                            }
                        }
                        if (options != null)
                        {
                            // As per MSDN documentation (https://msdn.microsoft.com/en-us/library/windows/apps/hh702394.aspx)
                            // the second param of Frame.Navigate must be a basic type otherwise Suspension manager will crash
                            // when serializing frame's state. So we serialize custom object using Json and pass that as the
                            // second param to avoid this crash.
                            frame.Navigate(typeof(PincodeDialog), PincodeOptions.ToJson(options));
                        }
                    }
                });
            }
        }
        public static void SavePinTimer()
        {
            MobilePolicy policy  = GetMobilePolicy();
            Account      account = AccountManager.GetAccount();

            if (account != null && policy != null && policy.ScreenLockTimeout > 0)
            {
                PlatformAdapter.SendToCustomLogger("AuthStorageHelper.SavePinTimer - saving pin timer", LoggingLevel.Verbose);
                AuthStorageHelper.GetAuthStorageHelper()
                .PersistData(true, PinBackgroundedTimeKey, DateTime.Now.ToUniversalTime().ToString());
            }
        }
        /// <summary>
        ///     Stores the pincode and associated mobile policy information including pin length and screen lock timeout.
        /// </summary>
        /// <param name="policy"></param>
        /// <param name="pincode"></param>
        public static void StorePincode(MobilePolicy policy, string pincode)
        {
            string hashed       = GenerateEncryptedPincode(pincode);
            var    mobilePolicy = new MobilePolicy
            {
                ScreenLockTimeout = policy.ScreenLockTimeout,
                PinLength         = policy.PinLength,
                PincodeHash       = Encryptor.Encrypt(hashed, pincode)
            };

            AuthStorageHelper.GetAuthStorageHelper().PersistPincode(mobilePolicy);
            PlatformAdapter.SendToCustomLogger("AuthStorageHelper.StorePincode - Pincode stored", LoggingLevel.Verbose);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Stores the pincode and associated mobile policy information including pin length and screen lock timeout.
        /// </summary>
        /// <param name="policy"></param>
        /// <param name="pincode"></param>
        public static void StorePincode(MobilePolicy policy, string pincode)
        {
            string hashed       = GenerateEncryptedPincode(pincode);
            var    mobilePolicy = new MobilePolicy
            {
                ScreenLockTimeout = policy.ScreenLockTimeout,
                PinLength         = policy.PinLength,
                PincodeHash       = EncryptionService.Encrypt(hashed, pincode)
            };

            GetAuthStorageHelper().PersistPincode(mobilePolicy);
            LoggingService.Log("Pincode stored", LoggingLevel.Verbose);
        }
        public static void TriggerBackgroundedPinTimer()
        {
            Account      account  = AccountManager.GetAccount();
            MobilePolicy policy   = AuthStorageHelper.GetMobilePolicy();
            bool         required = AuthStorageHelper.IsPincodeRequired();

            if (account != null)
            {
                if (required || (policy == null && account.Policy != null))
                {
                    LaunchPincodeScreen();
                }
            }
            else if (!required)
            {
                AuthStorageHelper.ClearPinTimer();
            }
        }
        /// <summary>
        ///     This will return true if a pincode is required before the app can be accessed.
        /// </summary>
        /// <returns></returns>
        public static bool IsPincodeRequired()
        {
            AuthStorageHelper auth = GetAuthStorageHelper();
            // a flag is set if the timer was exceeded at some point. Automatically return true if the flag is set.
            bool required = auth.RetrieveData(PincodeRequired) != null;

            if (required)
            {
                PlatformAdapter.SendToCustomLogger("AuthStorageHelper.IsPincodeRequired - Pincode is required", LoggingLevel.Verbose);
                return(true);
            }
            if (IsPincodeSet())
            {
                MobilePolicy policy = GetMobilePolicy();
                if (policy != null)
                {
                    string time = auth.RetrieveData(PinBackgroundedTimeKey);
                    if (time != null)
                    {
                        DateTime previous = DateTime.Parse(time);
                        DateTime current  = DateTime.Now.ToUniversalTime();
                        TimeSpan diff     = current.Subtract(previous);
                        if (diff.Minutes >= policy.ScreenLockTimeout)
                        {
                            // flag that requires pincode to be entered in the future. Until the flag is deleted a pincode will be required.
                            auth.PersistData(true, PincodeRequired, time);
                            PlatformAdapter.SendToCustomLogger("AuthStorageHelper.IsPincodeRequired - Pincode is required", LoggingLevel.Verbose);
                            return(true);
                        }
                    }
                }
            }
            // We aren't requiring pincode, so remove the flag.
            auth.DeleteData(PincodeRequired);
            PlatformAdapter.SendToCustomLogger("AuthStorageHelper.IsPincodeRequired - Pincode is not required", LoggingLevel.Verbose);
            return(false);
        }
        /// <summary>
        ///     Stores the pincode and associated mobile policy information including pin length and screen lock timeout.
        /// </summary>
        /// <param name="policy"></param>
        /// <param name="pincode"></param>
        public static void StorePincode(MobilePolicy policy, string pincode)
        {
            string hashed = GenerateEncryptedPincode(pincode);
            var mobilePolicy = new MobilePolicy
            {
                ScreenLockTimeout = policy.ScreenLockTimeout,
                PinLength = policy.PinLength,
                PincodeHash = EncryptionService.Encrypt(hashed, pincode)
            };

            GetAuthStorageHelper().PersistPincode(mobilePolicy);
            LoggingService.Log("Pincode stored", LoggingLevel.Verbose);
        }
 public void PersistPincode(MobilePolicy policy)
 {
     DeletePincode();
     var newPin = new PasswordCredential(PasswordVaultSecuredData, PasswordVaultPincode,
         JsonConvert.SerializeObject(policy));
     _vault.Add(newPin);
     LoggingService.Log("pincode added to vault",
         LoggingLevel.Verbose);
 }
 /// <summary>
 ///     Stores the pincode and associated mobile policy information including pin length and screen lock timeout.
 /// </summary>
 /// <param name="policy"></param>
 /// <param name="pincode"></param>
 public static void StorePincode(MobilePolicy policy, string pincode)
 {
     string hashed = GenerateEncryptedPincode(pincode);
     var mobilePolicy = new MobilePolicy
     {
         ScreenLockTimeout = policy.ScreenLockTimeout,
         PinLength = policy.PinLength,
         PincodeHash = Encryptor.Encrypt(hashed, pincode)
     };
     AuthStorageHelper.GetAuthStorageHelper().PersistPincode(mobilePolicy);
     PlatformAdapter.SendToCustomLogger("AuthStorageHelper.StorePincode - Pincode stored", LoggingLevel.Verbose);
 }
 public void PersistPincode(MobilePolicy policy)
 {
     DeletePincode();
     var newPin = new PasswordCredential(PasswordVaultSecuredData, PasswordVaultPincode,
         JsonConvert.SerializeObject(policy));
     _vault.Add(newPin);
     PlatformAdapter.SendToCustomLogger("AuthStorageHelper.PersistPincode - pincode added to vault",
         LoggingLevel.Verbose);
 }