示例#1
0
        public static string GetNewPassword(TcpClient clientConnection)
        {
            /////////////////////////////
            ///  PASSWORD VALIDATION  ///
            /////////////////////////////

            Console.WriteLine("Username validated");

            // Used to decide if the password is correctly validated.

            bool   passwordValidated = false;
            string encryptedPassword = null;

            SocketStream.SendMessage("Password must be between 8 and 15 characters, contain 1 lowercase, 1 uppercase letter and a digit.\n", clientConnection.GetStream());

            // While the user has not input a valid password, we must ask and check for a correct one.
            while (!passwordValidated)
            {
                SocketStream.SendMessage("Enter Password: "******"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,15}$"))
                {
                    // If the password contains a lower case and uppercase and at least 1 number.
                    passwordValidated = true;
                    encryptedPassword = PasswordEncryptor.GenerateNewPassword(userInputPassword);
                }
                else
                {
                    // The password is invalid
                    SocketStream.SendMessage("\nPassword invalid. Try again.\n", clientConnection.GetStream());
                    continue;
                }
            }

            return(encryptedPassword);
        }