Advertisement
Guest User

Password

a guest
May 11th, 2017
1,807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.08 KB | None | 0 0
  1. #------------------- FORMATING --------------------------
  2.  
  3. global line #Globalises a variable
  4. line = "="*64 #Sets the variable to "=" 64 times
  5. global line2
  6. line2 = ">"*64
  7.  
  8. #------------------- FORMATING --------------------------
  9.  
  10. def username_fn(): #Defines a function
  11.     print line2     #Prints line2
  12.     print "\t\t\tUser Name Creator" #prints to screen
  13.     print line2
  14.  
  15.     print line  #prints line1
  16.     first = raw_input("\tWhat is your first name? ").title() #Asks user for firstname
  17.     last = raw_input("\tWhat is your family name? ").title() #Asks user for family name
  18.     idnum = raw_input("\tWhat is your ID Number? ") #Asks for student ID number
  19.     username = first[0:3]+last[0:3]+str(idnum[-3:]) #Gets the first 3 letters of 'first', Gets the first 3 letters of 'last' and last 3 letters of 'idnum'
  20.     print line
  21.     print "Username: %s" % username #prints user's username
  22.     print line
  23.     return username #Returns the variable called username
  24.  
  25. def password_fn(): #Defines a function
  26.     print "\n\n"
  27.     print line2
  28.     print "\t\t\tPassword Creator"
  29.     print line2
  30.     print "Please make sure your password meets these requirements:\n"
  31.     print "\tBe at least 7 characters long"
  32.     print "\tMust contain at least 1 uppercase and 1 lowercase letter"
  33.     print "\tMust contain at least 1 numeric digit"
  34.     print line
  35.     loop = "true" #sets loop to "true"
  36.     while loop == "true": #while loop is true, run the following:
  37.          
  38.         password = raw_input("\tEnter a new password: ") #input field for a password
  39.  
  40.         digit = 0
  41.         upper = 0
  42.         lower = 0
  43.         for char in list(password): #Run this loop each character of the variable 'password'
  44.             if char.isdigit(): #if the character is a digit
  45.                 digit = digit+1 #add 1 to digit
  46.             elif char.isupper():#if the character is an uppercase
  47.                 upper = upper+1 #add 1 to upper
  48.             elif char.islower():#if the character is a lowecase
  49.                 lower = lower+1 #add 1 to lower
  50.         sum = digit+upper+lower #sum eqauls the values of digit+upper+lower
  51.         print line
  52.         sum_sw="" #sets the variable to an empty string
  53.         digit_sw=""#sets the variable to an empty string
  54.         upper_sw=""#sets the variable to an empty string
  55.         lower_sw=""#sets the variable to an empty string
  56.         if sum >= 7: #if 'sum' is equal or greater than 7
  57.             sum_sw="PASS" #sets string
  58.             print "Length Validation :  \t\t\t[PASS]" #prints to screen
  59.             print line
  60.         if sum < 7:#if 'sum' is lower than 7
  61.             print "Length Validation:  \t\t\t[FAIL]"#prints to screen
  62.             print line
  63.         if digit >= 1:#if greater or eqaul to 1
  64.             digit_sw="WORD"#sets string
  65.             print "Numeric Digit Validation:  \t\t[PASS]"#prints to screen
  66.             print line
  67.         if digit < 1:#if less than 1
  68.             print "Numeric Digit Validation:  \t\t[FAIL]"#prints to screen
  69.             print line
  70.         if upper >= 1:#if greater or eqaul to 1
  71.             upper_sw="VALIDATION"#sets string
  72.             print "Uppercase Validation:  \t\t\t[PASS]"#prints to screen
  73.             print line
  74.         if upper < 1:#if less than 1
  75.             print "Uppercase Validation:  \t\t\t[FAIL]"#prints to screen
  76.             print line
  77.         if lower >= 1:#if greater or eqaul to 1
  78.             lower_sw="CORRECT"#sets string
  79.             print "Lowercase Validation:  \t\t\t[PASS]"#prints to screen
  80.             print line
  81.         if lower < 1:#if less than 1
  82.             print "Lowercase Validation:  \t\t\t[FAIL]"#prints to screen
  83.             print line
  84.         else:
  85.             code = sum_sw+digit_sw+upper_sw+lower_sw #sets code to all the above strings
  86.             if code == "PASSWORDVALIDATIONCORRECT": #if code equals the correct phrase (needs all correct to pass)
  87.                 print line2
  88.                 print "\t\tPassword Validation Complete"
  89.                 print line2
  90.                 return password #returns password
  91.                 loop = "false" #sets loop to false
  92.             else:
  93.                 print line2
  94.                 print "\t\tPassword Validation Failed"
  95.                 print "\t\t\tTry Again"
  96.                 print line2
  97.                 loop = "true" #will run loop again
  98.  
  99. def login_fn(username, password): #defines a function, sending in variables called 'username' and 'password'
  100.     print "\n\n"
  101.     err_msg = line+"\n"+"Incorrect Username and/or Password"+"\n"+line #sets a variable called err_msg
  102.     loop = "yes" #sets loop to yes
  103.     while loop == "yes": #while loop is yes
  104.         print line2
  105.         print "\t\t\tLogin Procedure"
  106.         print line2
  107.         print "Type '?' for help, Type 'q' to terminate the login procedure"
  108.         print line
  109.         i_username = raw_input("Username: ") #asks for username
  110.         if i_username == "?": #if input eqauls "?"
  111.             print line
  112.             print "\t-Registered Users-"
  113.             print "Username:\t\t Password:\n"
  114.             print "JonStr401\t\t***5****Be**"
  115.             print "CarSur122\t\t2****at***"
  116.             print "%s\t\t%s" % (username, password)
  117.             print "RacLav863\t\t****G******21"
  118.             fkacc = "---\t\t\t---\n"
  119.             print fkacc*9
  120.             print line
  121.         elif i_username == "q" or i_username == "Q": #if input is "q" or "Q"
  122.             print line2
  123.             print "\t\tLogin Procedure Terminated"
  124.             print line2
  125.             return "\t\t\tThe User failed to login" #Return this message
  126.             loop = "no" #exits the loop
  127.              
  128.         elif i_username == username: #if the username is correct
  129.             i_password = raw_input("Password: ") #asks for password
  130.             if i_password == password: #if password is correct
  131.                 print line2
  132.                 print "\t\tLogin Procedure Completed"
  133.                 print line2
  134.                 return "\t\t\tThe User succesfully logged in" #Return this message
  135.                 loop = "no"
  136.                  
  137.             else:
  138.                 print err_msg #print err_msg
  139.         else:
  140.             print err_msg #print err_msg
  141.              
  142. def end(login): #defines a function, sending in the returned value from login_fn
  143.     print "\n\n"
  144.     print line2
  145.     print login
  146.     print line2
  147.     print "\t\t\tProgram Completed"
  148.     print line2
  149.      
  150. def func(): #defines a function
  151.      
  152.     username = username_fn() #sets the varible to the returned value from the function called
  153.     password = password_fn()#sets the varible to the returned value from the function called
  154.     login = login_fn(username, password)#sets the varible to the returned value from the function called and sends in two varibles
  155.     end(login) #calls the end function, sending in 'login'
  156.  
  157. def main(): #defines a function
  158.     play="yes" #play = yes
  159.     while play=="yes": #while play is yes
  160.         func() #call func
  161.         print "Run Again?"
  162.         play = raw_input("Yes or No? ").lower() #asks user to run program again
  163.     else:
  164.         print "Thanks for playing"
  165.  
  166. main() #calls main() function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement