예제 #1
0
        private static bool Authenticate(NntpClient client, string username, string password)
        {
            // try to authenticate with username and password from options
            if (!string.IsNullOrWhiteSpace(username) &&
                !string.IsNullOrWhiteSpace(password) &&
                client.Authenticate(username, password))
            {
                return true;
            }

            // get password and username if not provided in options
            for (var tries = 3; tries > 0; tries--)
            {
                // get username 
                string defaultUsername = string.IsNullOrWhiteSpace(username) ? null : $"[default = {username}]";
                Console.Write($"Username{defaultUsername}: ");
                string userName = Console.ReadLine();
                if (!string.IsNullOrWhiteSpace(userName))
                {
                    username = userName;
                }
                if (string.IsNullOrWhiteSpace(username))
                {
                    return false;
                }

                // get password
                Console.Write("Password: "******"Invalid credentials.");
            }
            return false;
        }