예제 #1
0
        public SharePointOnlineCredentials GetCredentialsForSharePointOnline(string userName, Uri urlToSite)
        {
            while (true)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("Enter your password for {0}: ", userName);
                var password = PasswordReader.GetConsoleSecurePassword();
                Console.ResetColor();
                Console.WriteLine();

                if (password != null && password.Length > 0)
                {
                    var credentials = new SharePointOnlineCredentials(userName, password);
                    if (AuthenticateUser(credentials, urlToSite))
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Account successfully authenticated!");
                        Console.ResetColor();

                        return(credentials);
                    }
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Couldn't authenticate user. Try again.");
                    Console.ResetColor();
                }
                else
                {
                    return(GetCredentialsForSharePointOnline(userName, urlToSite));
                }
            }
        }
예제 #2
0
        private static SecureString PromptForPassword(string userName)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("Enter your password for {0}: ", userName);
            var password = PasswordReader.GetConsoleSecurePassword();

            Console.ResetColor();
            Console.WriteLine();
            return(password);
        }