Пример #1
0
        public void Login()
        {
            //socket is established already
            //login
            SendPacket(
                new LoginPacket(
                    _parameters.ClientHostName,
                    _parameters.Username,
                    _parameters.Password,
                    _parameters.ProcessId,
                    _parameters.ApplicationName,
                    _parameters.Server,
                    "us_english",
                    _parameters.Charset,
                    "ADO.NET",
                    _environment.PacketSize,
                    new ClientCapabilityToken(_parameters.EnableServerPacketSize),
                    _parameters.EncryptPassword));

            var ackHandler            = new LoginTokenHandler();
            var envChangeTokenHandler = new EnvChangeTokenHandler(_environment, _parameters.Charset);
            var messageHandler        = new MessageTokenHandler(EventNotifier);

            ReceiveTokens(
                ackHandler,
                envChangeTokenHandler,
                messageHandler);

            messageHandler.AssertNoErrors();

            if (!ackHandler.ReceivedAck)
            {
                IsDoomed = true;
                throw new InvalidOperationException("No login ack found");
            }

            if (ackHandler.LoginStatus == LoginAckToken.LoginStatus.TDS_LOG_NEGOTIATE)
            {
                NegotiatePassword(ackHandler.Message.MessageId, ackHandler.Parameters.Parameters, _parameters.Password);
            }
            else if (ackHandler.LoginStatus != LoginAckToken.LoginStatus.TDS_LOG_SUCCEED)
            {
                throw new AseException("Login failed.\n", 4002); //just in case the server doesn't respond with an appropriate EED token
            }

            ServerVersion = ackHandler.Token.ProgramVersion;

            Created = DateTime.UtcNow;
            SetState(InternalConnectionState.Ready);
        }
Пример #2
0
        public void Login()
        {
            //socket is established already
            //login
            SendPacket(new LoginPacket(
                           _parameters.ClientHostName,
                           _parameters.Username,
                           _parameters.Password,
                           _parameters.ProcessId,
                           _parameters.ApplicationName,
                           _parameters.Server,
                           "us_english",
                           _parameters.Charset,
                           "ADO.NET",
                           _environment.PacketSize,
                           new CapabilityToken()));

            var ackHandler     = new LoginTokenHandler();
            var messageHandler = new MessageTokenHandler();

            ReceiveTokens(
                ackHandler,
                new EnvChangeTokenHandler(_environment),
                messageHandler);

            messageHandler.AssertNoErrors();

            if (!ackHandler.ReceivedAck)
            {
                IsDoomed = true;
                throw new InvalidOperationException("No login ack found");
            }

            ServerVersion = ackHandler.Token.ProgramVersion;

            Created = DateTime.UtcNow;
            SetState(InternalConnectionState.Ready);
        }
Пример #3
0
        private void DoEncrypt3Scheme(ParametersToken.Parameter[] parameters, string password)
        {
            var encryptedPassword = Encryption.EncryptPassword3((int)parameters[0].Value, (byte[])parameters[1].Value, (byte[])parameters[2].Value, Encoding.ASCII.GetBytes(password));

            SendPacket(new NormalPacket(Encryption.BuildEncrypt3Tokens(encryptedPassword)));

            // 5. Expect an ack
            var ackHandler            = new LoginTokenHandler();
            var envChangeTokenHandler = new EnvChangeTokenHandler(_environment, _parameters.Charset);
            var messageHandler        = new MessageTokenHandler(EventNotifier);

            ReceiveTokens(
                ackHandler,
                envChangeTokenHandler,
                messageHandler);

            messageHandler.AssertNoErrors();

            if (ackHandler.LoginStatus != LoginAckToken.LoginStatus.TDS_LOG_SUCCEED)
            {
                throw new AseException("Login failed.\n", 4002); //just in case the server doesn't respond with an appropriate EED token
            }
        }