Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #------------------- FORMATING --------------------------
- global line #Globalises a variable
- line = "="*64 #Sets the variable to "=" 64 times
- global line2
- line2 = ">"*64
- #------------------- FORMATING --------------------------
- def username_fn(): #Defines a function
- print line2 #Prints line2
- print "\t\t\tUser Name Creator" #prints to screen
- print line2
- print line #prints line1
- first = raw_input("\tWhat is your first name? ").title() #Asks user for firstname
- last = raw_input("\tWhat is your family name? ").title() #Asks user for family name
- idnum = raw_input("\tWhat is your ID Number? ") #Asks for student ID number
- 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'
- print line
- print "Username: %s" % username #prints user's username
- print line
- return username #Returns the variable called username
- def password_fn(): #Defines a function
- print "\n\n"
- print line2
- print "\t\t\tPassword Creator"
- print line2
- print "Please make sure your password meets these requirements:\n"
- print "\tBe at least 7 characters long"
- print "\tMust contain at least 1 uppercase and 1 lowercase letter"
- print "\tMust contain at least 1 numeric digit"
- print line
- loop = "true" #sets loop to "true"
- while loop == "true": #while loop is true, run the following:
- password = raw_input("\tEnter a new password: ") #input field for a password
- digit = 0
- upper = 0
- lower = 0
- for char in list(password): #Run this loop each character of the variable 'password'
- if char.isdigit(): #if the character is a digit
- digit = digit+1 #add 1 to digit
- elif char.isupper():#if the character is an uppercase
- upper = upper+1 #add 1 to upper
- elif char.islower():#if the character is a lowecase
- lower = lower+1 #add 1 to lower
- sum = digit+upper+lower #sum eqauls the values of digit+upper+lower
- print line
- sum_sw="" #sets the variable to an empty string
- digit_sw=""#sets the variable to an empty string
- upper_sw=""#sets the variable to an empty string
- lower_sw=""#sets the variable to an empty string
- if sum >= 7: #if 'sum' is equal or greater than 7
- sum_sw="PASS" #sets string
- print "Length Validation : \t\t\t[PASS]" #prints to screen
- print line
- if sum < 7:#if 'sum' is lower than 7
- print "Length Validation: \t\t\t[FAIL]"#prints to screen
- print line
- if digit >= 1:#if greater or eqaul to 1
- digit_sw="WORD"#sets string
- print "Numeric Digit Validation: \t\t[PASS]"#prints to screen
- print line
- if digit < 1:#if less than 1
- print "Numeric Digit Validation: \t\t[FAIL]"#prints to screen
- print line
- if upper >= 1:#if greater or eqaul to 1
- upper_sw="VALIDATION"#sets string
- print "Uppercase Validation: \t\t\t[PASS]"#prints to screen
- print line
- if upper < 1:#if less than 1
- print "Uppercase Validation: \t\t\t[FAIL]"#prints to screen
- print line
- if lower >= 1:#if greater or eqaul to 1
- lower_sw="CORRECT"#sets string
- print "Lowercase Validation: \t\t\t[PASS]"#prints to screen
- print line
- if lower < 1:#if less than 1
- print "Lowercase Validation: \t\t\t[FAIL]"#prints to screen
- print line
- else:
- code = sum_sw+digit_sw+upper_sw+lower_sw #sets code to all the above strings
- if code == "PASSWORDVALIDATIONCORRECT": #if code equals the correct phrase (needs all correct to pass)
- print line2
- print "\t\tPassword Validation Complete"
- print line2
- return password #returns password
- loop = "false" #sets loop to false
- else:
- print line2
- print "\t\tPassword Validation Failed"
- print "\t\t\tTry Again"
- print line2
- loop = "true" #will run loop again
- def login_fn(username, password): #defines a function, sending in variables called 'username' and 'password'
- print "\n\n"
- err_msg = line+"\n"+"Incorrect Username and/or Password"+"\n"+line #sets a variable called err_msg
- loop = "yes" #sets loop to yes
- while loop == "yes": #while loop is yes
- print line2
- print "\t\t\tLogin Procedure"
- print line2
- print "Type '?' for help, Type 'q' to terminate the login procedure"
- print line
- i_username = raw_input("Username: ") #asks for username
- if i_username == "?": #if input eqauls "?"
- print line
- print "\t-Registered Users-"
- print "Username:\t\t Password:\n"
- print "JonStr401\t\t***5****Be**"
- print "CarSur122\t\t2****at***"
- print "%s\t\t%s" % (username, password)
- print "RacLav863\t\t****G******21"
- fkacc = "---\t\t\t---\n"
- print fkacc*9
- print line
- elif i_username == "q" or i_username == "Q": #if input is "q" or "Q"
- print line2
- print "\t\tLogin Procedure Terminated"
- print line2
- return "\t\t\tThe User failed to login" #Return this message
- loop = "no" #exits the loop
- elif i_username == username: #if the username is correct
- i_password = raw_input("Password: ") #asks for password
- if i_password == password: #if password is correct
- print line2
- print "\t\tLogin Procedure Completed"
- print line2
- return "\t\t\tThe User succesfully logged in" #Return this message
- loop = "no"
- else:
- print err_msg #print err_msg
- else:
- print err_msg #print err_msg
- def end(login): #defines a function, sending in the returned value from login_fn
- print "\n\n"
- print line2
- print login
- print line2
- print "\t\t\tProgram Completed"
- print line2
- def func(): #defines a function
- username = username_fn() #sets the varible to the returned value from the function called
- password = password_fn()#sets the varible to the returned value from the function called
- login = login_fn(username, password)#sets the varible to the returned value from the function called and sends in two varibles
- end(login) #calls the end function, sending in 'login'
- def main(): #defines a function
- play="yes" #play = yes
- while play=="yes": #while play is yes
- func() #call func
- print "Run Again?"
- play = raw_input("Yes or No? ").lower() #asks user to run program again
- else:
- print "Thanks for playing"
- main() #calls main() function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement