コード例 #1
0
        public static void CreateNameAndPassword(Player player, bool characterLoop)
        {
            Console.Clear();
            //Create user name
            Console.Write("Enter your name ==> ");
            string playerName = Console.ReadLine();

            player.Name = playerName;

            do
            {
                //Create Password
                Console.WriteLine(StandardMessages.DisplayPasswordCreationInformation());
                Console.Write("Enter your Password ==> ");
                string passWord1 = Console.ReadLine();
                player.Password = passWord1;
                Console.Write("Reenter your Password ==> ");
                string passWord2 = Console.ReadLine();
                //Decision structure to confirm password guidelines
                if (passWord1 != passWord2)
                {
                    Console.WriteLine("Passwords do not match!");
                    player.Password = "******";
                }
                else if (passWord1.Length < 8)
                {
                    Console.WriteLine("Password is not long enough!");
                    player.Password = "******";
                }
                else if (passWord1.Length > 15)
                {
                    Console.WriteLine("Password is to long!");
                    player.Password = "******";
                }
                else
                {
                    Console.WriteLine("Great Job! Press enter to continue.");
                    characterLoop = true;
                }
                Console.ReadLine();
                Console.Clear();
            } while (characterLoop == false);
        }
コード例 #2
0
        public static void CreateNameAndPassword(Character player)
        {
            bool characterLoop = false;

            Console.Clear();
            char ch = '!';

            //Display username/password title block
            Console.WriteLine(GameLibrary.StandardMessages.DisplayNamePasswordTitle());
            //Get user name from user
            Console.Write("Enter your name ==> ");
            string playerName = Console.ReadLine();

            player.Name = playerName;
            do
            {
                //Create Password
                Console.WriteLine(StandardMessages.DisplayPasswordCreationInformation());
                //Enter password
                Console.Write("Enter your Password ==> ");
                string passWord1 = Console.ReadLine();
                player.PlayerPassword = passWord1;
                //Reenter password to confirm they match
                Console.Write("Reenter your Password ==> ");
                string passWord2 = Console.ReadLine();
                //Determine password length meets guidelines
                if (passWord1.Length < 8 || passWord1.Length > 15)
                {
                    Console.WriteLine("Password must be 8 or more characters and not to exceed 15 characters!");
                    Console.ReadLine();
                    Console.Clear();
                }
                else if (passWord1.Length >= 8 || passWord1.Length <= 15)
                {
                    for (int i = 0; i < passWord1.Length; i++)
                    {
                        //Check password for 1 uppercase, 1 lowercase, 1 digit, and 1 punctuation/////////////////////////////////////
                        if (!(char.IsUpper(passWord1[i])))
                        {
                            //player.Password = "******";
                        }
                        else if (char.IsUpper(passWord1[i]))
                        {
                            for (i = 0; i < passWord1.Length; i++)
                            {
                                if (!(char.IsLower(passWord1[i])))
                                {
                                    //player.Password = "******";
                                }
                                else if (char.IsLower(passWord1[i]))
                                {
                                    for (i = 0; i < passWord1.Length; i++)
                                    {
                                        if (!(char.IsDigit(passWord1[i])))
                                        {
                                            //player.Password = "******";
                                        }
                                        else if (char.IsDigit(passWord1[i]))
                                        {
                                            for (i = 0; i < passWord1.Length; i++)
                                            {
                                                if (!(char.IsPunctuation(passWord1[i])))
                                                {
                                                    //player.Password = "******";
                                                }
                                                else if (char.IsPunctuation(passWord1[i]))
                                                {
                                                    characterLoop = true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
                if (characterLoop == false)
                {
                    Console.WriteLine("You failed to create an appropriate password! Try again!");
                }
                //Clear current screen
                Console.Clear();
            } while (characterLoop == false);
            //DIsplay password requirements met to user
            Console.WriteLine("Goodjob! Your password met the requirements. \n" +
                              "Press Enter...");
            Console.ReadLine();
        }