Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / IsOwnerPassword Method
Example





In This Topic
    IsOwnerPassword Method (GdPicturePDF)
    In This Topic
    Returns if the password provided with the SetPassword method was the owner password. You only need to provide the correct password once when using the 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 IsEncrypted method and in the 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 SetPassword method is the owner password, otherwise false. Please always use the GetStat method to determine if this method has been successful.
    Remarks
    Please note that this method is only allowed for use with non-encrypted documents.

    It is recommend to use the 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 oGdPicturePDF As New GdPicturePDF()
    'Please see the example in the SetPassword method for creating this file.
    If oGdPicturePDF.LoadFromFile("encrypted.pdf", False) = GdPictureStatus.OK Then
        Dim PassOk As Boolean = False
        Dim isEncrypted As Boolean = oGdPicturePDF.IsEncrypted()
        Dim status As GdPictureStatus = oGdPicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            If isEncrypted Then
                If oGdPicturePDF.SetPassword("") = GdPictureStatus.OK Then
                    PassOk = True
                Else
                'Try this call also with the "owner" password.
                    If oGdPicturePDF.SetPassword("user") = GdPictureStatus.OK Then
                        PassOk = True
                        If PassOk = True Then
                            Dim isOwner As Boolean = oGdPicturePDF.IsOwnerPassword()
                            status = oGdPicturePDF.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
    oGdPicturePDF.Dispose()
    string caption = "Example: IsOwnerPassword";
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    //Please see the example in the SetPassword method for creating this file.
    if (oGdPicturePDF.LoadFromFile("encrypted.pdf", false) == GdPictureStatus.OK)
    {
        bool PassOk = false;
        bool isEncrypted = oGdPicturePDF.IsEncrypted();
        GdPictureStatus status = oGdPicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            if (isEncrypted)
            {
                if (oGdPicturePDF.SetPassword("") == GdPictureStatus.OK)
                {
                    PassOk = true;
                }
                else
                {
                    //Try this call also with the "owner" password.
                    if (oGdPicturePDF.SetPassword("user") == GdPictureStatus.OK)
                    {
                        PassOk = true;
                        if (PassOk == true)
                        {
                            bool isOwner = oGdPicturePDF.IsOwnerPassword();
                            status = oGdPicturePDF.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);
    }
    oGdPicturePDF.Dispose();
    See Also