Example #1
0
        /// <summary>
        ///     Use a password to authenticate with a VNC Host. NOTE: This is only necessary if Connect() returns TRUE.
        /// </summary>
        /// <param name="password">The password to use.</param>
        /// <returns>Returns True if Authentication worked, otherwise False.</returns>
        public bool Authenticate(string password)
        {
            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            // If new Security Types are supported in future, add the code here.  For now, only
            // VNC Authentication is supported.
            if (securityType == 2)
            {
                PerformVncAuthentication(password);
            }
            else
            {
                throw new NotSupportedException(
                          "Unable to Authenticate with Server. The Server uses an Authentication scheme unknown to the client.");
            }

            if (rfb.ReadSecurityResult() == 0)
            {
                return(true);
            }

            // Authentication failed, and if the server is using Protocol version 3.8, a
            // plain text message follows indicating why the error happend.  I'm not
            // currently using this message, but it is read here to clean out the stream.
            // In earlier versions of the protocol, the server will just drop the connection.
            if (rfb.ServerVersion == 3.8)
            {
                rfb.ReadSecurityFailureReason();
            }
            rfb.Close(); // TODO: Is this the right place for this???
            return(false);
        }