BeginAuthenticateAsClient() public method

public BeginAuthenticateAsClient ( AsyncCallback asyncCallback, object asyncState ) : IAsyncResult
asyncCallback AsyncCallback
asyncState object
return IAsyncResult
Ejemplo n.º 1
0
        private void AuthCallback(IAsyncResult ar)
        {
            try
            {
                NegotiateStream nsCb = (NegotiateStream)ar.AsyncState;
                nsCb.EndAuthenticateAsClient(ar);
                nsCb.BeginRead(buffer, 0, buffer.Length, ReceiveCallback, nsCb);
                authenticated = true;
            }
            catch (Exception e)
            {
                authenticated = false;
                Console.WriteLine(e.Message);

                Console.WriteLine("Введите логин:");
                login = Console.ReadLine();
                while (login.Length == 0)
                {
                    Console.WriteLine("Введите логин:");
                    login = Console.ReadLine();
                }
                Console.WriteLine("Введите пароль:");
                password = Console.ReadLine();
                nws = new NetworkStream(socket);
                ns = new NegotiateStream(nws, true);
                netCred = new NetworkCredential(login, password);
                ns.BeginAuthenticateAsClient(netCred, String.Empty, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Delegation, AuthCallback, ns);
            }
        }
Ejemplo n.º 2
0
        private void ConnectCallback(IAsyncResult ar)
        {
            try
            {
                socket = (Socket)ar.AsyncState;
                socket.EndConnect(ar);
                nws = new NetworkStream(socket);
                ns = new NegotiateStream(nws, true);
                netCred = new NetworkCredential(login, password);
                ns.BeginAuthenticateAsClient(netCred, String.Empty, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Delegation, AuthCallback, ns);
                successful = true;
            }
            catch (Exception e)
            {
                successful = false;
                Console.WriteLine(e.Message);

                Console.WriteLine("Введите IP-адрес:");
                ip = Console.ReadLine();
                Console.WriteLine("Введите логин:");
                login = Console.ReadLine();
                while (login.Length == 0)
                {
                    Console.WriteLine("Введите логин:");
                    login = Console.ReadLine();
                }
                Console.WriteLine("Введите пароль:");
                password = Console.ReadLine();

                IPAddress tryIp;
                while (!IPAddress.TryParse(ip, out tryIp))
                {
                    Console.WriteLine("Введите IP-адрес:");
                    ip = Console.ReadLine();
                    Console.WriteLine("Введите логин:");
                    login = Console.ReadLine();
                    while (login.Length == 0)
                    {
                        Console.WriteLine("Введите логин:");
                        login = Console.ReadLine();
                    }
                    Console.WriteLine("Введите пароль:");
                    password = Console.ReadLine();
                }

                Connect(ip, port, login, password);
            }
        }