'Username and Password Variable Incorrect

Helo guys

i'm trying to create a login system, it's run normally when i input username and password directlt after i signed up on my own code, but when i try to login using false username or password bruteforcely variable "p" or "u" is changed by itself. I dunno why it's happened here's my code

sorry for my bad english and my bad code(it's weird"), i'm new in programming language and python "i've tried my best" so if anyone wants to fix my code or something else please help me, 1 more question is there any code to loop when the input is false? i used a function that call the lastest function if the input is false

import os
import sys
import re

def apus():
       sys.stdout.write(CURSOR_UP_ONE)
       sys.stdout.write(ERASE_LINE)

CURSOR_UP_ONE = '\x1b[1A'

ERASE_LINE = '\x1b[2K'

def main():

         os.system("cls")
         print(""""
           Welcome To X Bank
           Enter Any Key To Continue
         """)
         x = input()
         menu()

 def menu():

        os.system('cls')
        print("------------------------------------------------------------------------")
        print('''
                 Don't Have An Account Yet? Please Sign Up
                       
                1. Login
                2. Sign Up
        ''')
        print("------------------------------------------------------------------------")
        opsimenu()

 def opsimenu():

     #os.system("cls")
     a = int(input())
     os.system("cls")
     if a == 1:
         login()
     elif a == 2:
          signu()
     
     else:
          menu()

 def ulog():

          login()

 def login():

      os.system('cls')
      print("Enter Your Username And Password \n \n")
      C = input("Username = ")
      D = input("Password = ")

      while True:
               if C == u and D == p:
               login2()
               break
            else:
                print("Your Username Or Password Is Incorrect")
                ulog()

 def login2():

     os.system("cls")
     print("Login Succesful")


 def signu():

     global Address
     global Name
     #print("\n ")
     print("""
     Your Username And Password *
     *Must be at least 8 characters.
     *must be between [a-z]
     *Must be at least one alphabet should be of Upper Case [A-Z]
     *Must be at least 1 number or digit between [0-9].
     *Must be at least 1 character from [!@#$%^&*].
     """)
     Name      = str(input("Full Name:"))
     Address   = str(input("Address: "))
     enteruser()

 def signup():

      enteruser()

 def enteruser():

     global u
     Username  = (input("Username:"))
     flag = 0
     while True:
           if (len(Username) < 8):
              flag = -1
              break
     elif not re.search("[a-z]", Username):
           flag = -1
           break
     elif not re.search("[A-Z]", Username):
           flag = -1
           break
     elif not re.search("[0-9]", Username):
           flag = -1
           break
     elif not re.search("[!@#$%^&*]", Username):
           flag = -1
           break
     elif re.search("\s", Username):
           flag = -1
           break
     else:
           flag = 0
           break

     if flag == -1:
         apus()
         #print("Invalid Username")
         signup()

      u = Username
      pw()

  def ulangpw():
      pw()

  def pw():

      global p
      Password   = str(input("Password:"))
      while True:
          if (len(Password) < 8):
              flag = -1
              break
      elif not re.search("[a-z]", Password):
              flag = -1
              break
      elif not re.search("[A-Z]", Password):
              flag = -1
              break
      elif not re.search("[0-9]", Password):
              flag = -1
              break
      elif not re.search("[!@#$%^&*]", Password):
              flag = -1
              break
      elif re.search("\s", Password):
              flag = -1
              break
      else:
           flag = 0
           break

      if flag == -1:
          print("Invalid Password")
          apus()
          apus()
          ulangpw()
      p = Password
      os.system("cls")
      validating()

  def validating():

     print("             ---------------------------------------------------")
     print("                 You have successfully created your account.\n                 Press Any Key To Login. \n \n                 Validating Your Data")
     print("\n                 •  Full Name ="+ Name)
     print("                 •  Address   ="+ Address)
     print("                 •  Username  ="+ u)
     print("                 •  Password  ="+ p)
     print("             ---------------------------------------------------")
     #p = Password
     confirm = str(input("\n               Make sure all registration data that is filled in is correct> Y/N "))

while True:
    if confirm == "Y" or confirm =="y":
        login()
        break
    elif confirm == "N" or confirm == 'n':
      os.system("cls")
      signu()
      break
    else:
        confirm = str(input("\n               Make sure all registration data that is filled in is correct> Y/N ="))
        break
 >main()


Solution 1:[1]

python wont print this:

 print("""
     Your Username And Password *
     *Must be at least 8 characters.
     *must be between [a-z]
     *Must be at least one alphabet should be of Upper Case [A-Z]
     *Must be at least 1 number or digit between [0-9].
     *Must be at least 1 character from [!@#$%^&*].
     """)

Because it is syntax for uncommenting text

""" multiline comment line 1
    multiline comment line 2 """

You have to use quotes like

 print("Hi Dad")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andre Juntermanns