public AuthenticationService(long masterIdentifier, SecureString password)
        {
            string filePath = SettingsUtility.GetAuthenticationSettingsFilePath(masterIdentifier);

            if (!File.Exists(filePath))
            {
                throw new KeyNotFoundException($"identifier={masterIdentifier}");
            }

            _authenticationSettings = AuthenticationSettingsExtensions.Load(filePath, password);
            Initializer             = new ExtendedInitializer(this);

            _password = password;
        }
        public void Register(IAuthenticationSettings contractObject, SecureString password)
        {
            if (null == contractObject)
            {
                throw new ArgumentNullException(nameof(contractObject));
            }

            if (null != password && 0 == password.Length)
            {
                password = null;
            }

            string authenticationSettingsFilePath = SettingsUtility.GetAuthenticationSettingsFilePath(contractObject.Identifier);

            if (File.Exists(authenticationSettingsFilePath))
            {
                throw new DuplicateRegistrationException(
                          string.Format(CultureInfo.InvariantCulture,
                                        Resources.EntranceService_Register_WMID__0_000000000000__already_registered_in_the_program_, contractObject.Identifier));
            }

            var authenticationSettings = contractObject as AuthenticationSettings ?? AuthenticationSettings.Create(contractObject);

            if (null == authenticationSettings.RequestNumberSettings)
            {
                authenticationSettings.RequestNumberSettings =
                    new RequestNumberSettings
                {
                    Method = RequestNumberGenerationMethod.UnixTimestamp
                }
            }
            ;

            authenticationSettings.Save(authenticationSettingsFilePath, password);

            if (!ApplicationUtility.IsRunningOnMono)
            {
                try
                {
                    File.Encrypt(authenticationSettingsFilePath);
                    File.SetAttributes(authenticationSettingsFilePath, FileAttributes.Hidden | FileAttributes.Encrypted);
                }
                catch (Exception exception)
                {
                    Logger.Error(exception.Message, exception);
                }
            }
        }
        public void RemoveRegistration(long identifier)
        {
            string authenticationSettingsFilePath = SettingsUtility.GetAuthenticationSettingsFilePath(identifier);

            if (File.Exists(authenticationSettingsFilePath))
            {
                File.Delete(authenticationSettingsFilePath);
            }

            string settingsFilePath = SettingsUtility.GetSettingsFilePath(identifier);

            if (File.Exists(settingsFilePath))
            {
                File.Delete(settingsFilePath);
            }
        }
        public bool CheckRegistration(long identifier)
        {
            string authenticationSettingsFilePath = SettingsUtility.GetAuthenticationSettingsFilePath(identifier);

            return(File.Exists(authenticationSettingsFilePath));
        }
        private void Save()
        {
            string filePath = SettingsUtility.GetAuthenticationSettingsFilePath(_authenticationSettings.Identifier);

            _authenticationSettings.Save(filePath, _password);
        }