public void SaveCredentials( )
        {
            if (!DPAPI.CanUseDPAPI)
            {
                return;
            }

            byte[] data;
            using (MemoryStream stream = new MemoryStream( ))
                using (BinaryWriter writer = new BinaryWriter(stream)) {
                    writer.Write(Username);
                    writer.Write(Password);
                    data = stream.GetBuffer( );
                }

            DPAPI dpapi = new DPAPI( );

            dpapi.Entropy = GetEntropy( );
            byte[] cipher = dpapi.Encrypt(data);
            using (FileStream stream = new FileStream(PersistFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
                using (BinaryWriter writer = new BinaryWriter(stream)) {
                    writer.Write(cipher.Length);
                    writer.Write(cipher);
                }
        }
        public bool LoadCredentials( )
        {
            if (!DPAPI.CanUseDPAPI)
            {
                return(false);
            }
            if (File.Exists(PersistFile))
            {
                byte[] cipher;
                using (FileStream stream = new FileStream(PersistFile, FileMode.Open, FileAccess.Read, FileShare.None))
                    using (BinaryReader reader = new BinaryReader(stream)) {
                        int length = reader.ReadInt32( );
                        cipher = reader.ReadBytes(length);
                    }

                DPAPI dpapi = new DPAPI( );
                dpapi.Entropy = GetEntropy( );

                try {
                    byte[] data = dpapi.Decrypt(cipher);

                    using (MemoryStream stream = new MemoryStream(data))
                        using (BinaryReader reader = new BinaryReader(stream)) {
                            Username = reader.ReadString( );
                            Password = reader.ReadString( );
                        }
                } catch (Exception) {
                    return(false);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void SaveCredentials( )
        {
            if ( !DPAPI.CanUseDPAPI )
                return;

            byte[] data;
            using ( MemoryStream stream = new MemoryStream ( ) )
            using ( BinaryWriter writer = new BinaryWriter ( stream ) ) {
                writer.Write ( Username );
                writer.Write ( Password );
                data = stream.GetBuffer ( );
            }

            DPAPI dpapi = new DPAPI ( );
            dpapi.Entropy = GetEntropy ( );
            byte[] cipher = dpapi.Encrypt ( data );
            using ( FileStream stream = new FileStream ( PersistFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None ) )
            using ( BinaryWriter writer = new BinaryWriter ( stream ) ) {
                writer.Write ( cipher.Length );
                writer.Write ( cipher );
            }
        }
        public bool LoadCredentials( )
        {
            if ( !DPAPI.CanUseDPAPI )
                return false;
            if ( File.Exists ( PersistFile ) ) {
                byte[] cipher;
                using ( FileStream stream = new FileStream ( PersistFile, FileMode.Open, FileAccess.Read, FileShare.None ) )
                using ( BinaryReader reader = new BinaryReader ( stream ) ) {
                    int length = reader.ReadInt32 ( );
                    cipher = reader.ReadBytes ( length );
                }

                DPAPI dpapi = new DPAPI ( );
                dpapi.Entropy = GetEntropy ( );

                try {
                    byte[] data = dpapi.Decrypt ( cipher );

                    using ( MemoryStream stream = new MemoryStream ( data ) )
                    using ( BinaryReader reader = new BinaryReader ( stream ) ) {
                        Username = reader.ReadString ( );
                        Password = reader.ReadString ( );
                    }
                } catch ( Exception ) {
                    return false;
                }

                return true;
            } else
                return false;
        }