Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / IsOwnerPassword Method

IsOwnerPassword Method (GdPicturePDF)

In This Topic
Returns if the password provided with the GdPicturePDF.SetPassword method was the owner password. You only need to provide the correct password once when using the GdPicturePDF.SetPassword method. Any other subsequent attempt to set a password using this method will fail.

Please read more about the password and permissions security in the GdPicturePDF.IsEncrypted method and in the GdPicturePDF.SetPassword method.

Syntax
'Declaration

 

Public Function IsOwnerPassword() As Boolean
public bool IsOwnerPassword()
public function IsOwnerPassword(): Boolean; 
public function IsOwnerPassword() : boolean;
public: bool IsOwnerPassword(); 
public:

bool IsOwnerPassword(); 

Return Value

true if the password provided with the GdPicturePDF.SetPassword method is the owner password, otherwise false. The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GdPicturePDF.GetStat method to identify the specific reason for the method's failure, if any.

Example
How to check if you have provided the correct owner password.
Dim caption As String = "Example: IsOwnerPassword"

Dim gdpicturePDF As New GdPicturePDF()

'Please see the example in the SetPassword method for creating this file.

If gdpicturePDF.LoadFromFile("encrypted.pdf", False) = GdPictureStatus.OK Then

    Dim PassOk As Boolean = False

    Dim isEncrypted As Boolean = gdpicturePDF.IsEncrypted()

    Dim status As GdPictureStatus = gdpicturePDF.GetStat()

    If status = GdPictureStatus.OK Then

        If isEncrypted Then

            If gdpicturePDF.SetPassword("") = GdPictureStatus.OK Then

                PassOk = True

            Else

            'Try this call also with the "owner" password.

                If gdpicturePDF.SetPassword("user") = GdPictureStatus.OK Then

                    PassOk = True

                    If PassOk = True Then

                        Dim isOwner As Boolean = gdpicturePDF.IsOwnerPassword()

                        status = gdpicturePDF.GetStat()

                        If status = GdPictureStatus.OK Then

                            If isOwner Then

                                MessageBox.Show("The password you have provided is the owner password.", caption)

                            Else

                                MessageBox.Show("The password you have provided is the user password.", caption)

                            End If

                        End If

                    End If

                End If

            End If

            If PassOk = False Then

                MessageBox.Show("You have provided a wrong password.", caption)

            End If

        Else

            MessageBox.Show("This PDF is not encrypted.", caption)

        End If

    End If

Else

    MessageBox.Show("The file can't be loaded.", caption)

End If

gdpicturePDF.Dispose()
string caption = "Example: IsOwnerPassword";

GdPicturePDF gdpicturePDF = new GdPicturePDF();

//Please see the example in the SetPassword method for creating this file.

if (gdpicturePDF.LoadFromFile("encrypted.pdf", false) == GdPictureStatus.OK)

{

    bool PassOk = false;

    bool isEncrypted = gdpicturePDF.IsEncrypted();

    GdPictureStatus status = gdpicturePDF.GetStat();

    if (status == GdPictureStatus.OK)

    {

        if (isEncrypted)

        {

            if (gdpicturePDF.SetPassword("") == GdPictureStatus.OK)

            {

                PassOk = true;

            }

            else

            {

                //Try this call also with the "owner" password.

                if (gdpicturePDF.SetPassword("user") == GdPictureStatus.OK)

                {

                    PassOk = true;

                    if (PassOk == true)

                    {

                        bool isOwner = gdpicturePDF.IsOwnerPassword();

                        status = gdpicturePDF.GetStat();

                        if (status == GdPictureStatus.OK)

                        {

                            if (isOwner)

                            {

                                MessageBox.Show("The password you have provided is the owner password.", caption);

                            }

                            else

                            {

                                MessageBox.Show("The password you have provided is the user password.", caption);

                            }

                        }

                    }

                }

            }

            if (PassOk == false)

            {

                MessageBox.Show("You have provided a wrong password.", caption);

            }

        }

        else

        {

            MessageBox.Show("This PDF is not encrypted.", caption);

        }

    }

}

else

{

    MessageBox.Show("The file can't be loaded.", caption);

}

gdpicturePDF.Dispose();
See Also