Beispiel #1
0
        internal void Authenticate(bool reset)
        {
            CheckConstraints();

            MyCatPacket packet = driver.Packet;

            // send auth response
            packet.WriteString(GetUsername());

            // now write the password
            WritePassword(packet);

            if ((Flags & ClientFlags.CONNECT_WITH_DB) != 0 || reset)
            {
                if (!String.IsNullOrEmpty(Settings.Database))
                {
                    packet.WriteString(Settings.Database);
                }
            }

            if (reset)
            {
                packet.WriteInteger(8, 2);
            }

            if ((Flags & ClientFlags.PLUGIN_AUTH) != 0)
            {
                packet.WriteString(PluginName);
            }

            driver.SetConnectAttrs();
            driver.SendPacket(packet);
            //read server response
            packet = ReadPacket();
            byte[] b = packet.Buffer;
            if (b[0] == 0xfe)
            {
                if (packet.IsLastPacket)
                {
                    driver.Close(true);
                    throw new MyCatException(Resources.OldPasswordsNotSupported);
                }
                else
                {
                    HandleAuthChange(packet);
                }
            }
            driver.ReadOk(false);
            AuthenticationSuccessful();
        }
Beispiel #2
0
        private void WritePassword(MyCatPacket packet)
        {
            bool   secure   = (Flags & ClientFlags.SECURE_CONNECTION) != 0;
            object password = GetPassword();

            if (password is string)
            {
                if (secure)
                {
                    packet.WriteLenString((string)password);
                }
                else
                {
                    packet.WriteString((string)password);
                }
            }
            else if (password == null)
            {
                packet.WriteByte(0);
            }
            else if (password is byte[])
            {
                packet.Write(password as byte[]);
            }
            else
            {
                throw new MyCatException("Unexpected password format: " + password.GetType());
            }
        }