Advertisement
Guest User

Untitled

a guest
Nov 13th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.44 KB | None | 0 0
  1. import random, time
  2.  
  3. print("Tips for creating a good password:",\
  4.       "\n\t----1.Use a combination of uppercase and lowercase letters.\n",\
  5.       "\n\t----2.Use numbers\n",\
  6.       "\n\t----3.Use special characters like '!£$%^&'.\n",\
  7.       "\n\t----Remember that your password has to be between 8 and 14 characters.\n",\
  8.       "=" * 75
  9.       )
  10.  
  11. time.sleep(1)
  12.  
  13. def set_userName():
  14.     global userName
  15.  
  16.     print("\n\t----Enter your username")
  17.     userName = input("\n\t\tUsername: ")
  18.     print("\n\t----Your username was saved.\n")
  19.  
  20.     set_userQuestions()
  21.  
  22. def set_userQuestions():
  23.     global secQuestions, ansQuestions, userQuestions
  24.     print("=" * 75)
  25.  
  26.     secQuestions = ["What is the title of your favourite movie?",\
  27.                     "Who is your favourite music artist?",\
  28.                     "What is your mother's maiden name?"]
  29.  
  30.     userQuestions = []
  31.  
  32.     for x in range(0, len(secQuestions)):
  33.         print("\t\t", secQuestions[x])
  34.  
  35.         ansQuestions = input("\n\t\tAnswer: ")
  36.         userQuestions.append(ansQuestions)
  37.  
  38.         print("=" * 25)
  39.  
  40.     set_userPassword()
  41.  
  42.  
  43. def set_userPassword():
  44.     global userName, userPassword
  45.  
  46.     print("\n\t----Create your password")
  47.     userPassword = input("\n\t\tPassword: ")
  48.  
  49.     print("\n\t----Confirm your password")
  50.     confirmPassword = input("\n\t\tConfirmation: ")
  51.  
  52.     if confirmPassword == userPassword and (len(userPassword) >= 8 and len(userPassword) <= 14):
  53.         print("\n\t----Your password was saved.")
  54.         user_login(userName, userPassword)
  55.  
  56.     elif (confirmPassword == userPassword) and not (len(userPassword) >= 8 and len(userPassword) <= 14):
  57.         print("\n\t----Your password is too short or too long. Remember it has to be between 8 and 14 characters.")
  58.         set_userPassword()
  59.        
  60.     else:
  61.         print("\n\t----Your passwords don't match.")
  62.         time.sleep(1)
  63.         set_userPassword()
  64.  
  65. def user_login(userName, userPassword):
  66.     print("=" * 75)
  67.     tries = 0
  68.    
  69.     for tries in range(0, 2):
  70.  
  71.         loginUsername = input("\n\t\tEnter your username: ")
  72.         loginPassword = input("\n\t\tEnter your password: ")
  73.  
  74.         if loginPassword == userPassword and loginUsername == userName:
  75.             time.sleep(0.5)
  76.             detail_registration()
  77.  
  78.         else:
  79.             print("\n\t----Username or password wrong, check again")
  80.             tries +=1
  81.  
  82.             if tries == 2:
  83.                 print("\n\t----Your account has been blocked. You can recover your password by answering one of the available security questions")
  84.                 security_questions(tries)
  85.  
  86. def security_questions(tries):
  87.     global secQuestions, ansQuestions
  88.  
  89.     print("=" * 75)
  90.     secNo = random.randint(1, 3)
  91.  
  92.     for i in range(1, 3):
  93.         if secNo == i:
  94.             print(secQuestions[i])
  95.             checkQuestion = input("Answer: ")
  96.  
  97.             if checkQuestion == ansQuestions:
  98.                 detail_registration()
  99.                
  100.             else:
  101.                 print("\n\t----Your account has been blocked, call the customer service to retreive it.")
  102.  
  103. def detail_registration():
  104.     global userName, userQuestions, userPassword
  105.    
  106.     print("=" * 75)
  107.     print("\t----Welcome\n")
  108.  
  109.     detailDict = {
  110.         "username": userName,
  111.         "password": userPassword,
  112.         "question_1": userQuestions[0],
  113.         "question_2": userQuestions[1],
  114.         "question_3": userQuestions[2]
  115.                 }
  116.  
  117.     print("\t\tUsername: ", "".join(detailDict["username"]),\
  118.         "\n\n\t\tPassword: ", "".join(detailDict["password"]),\
  119.         "\n\n\t\tWhat is the title of your favourite movie? ", "".join(detailDict["question_1"]),\
  120.         "\n\n\t\tWho is your favourite artist? ", "".join(detailDict["question_2"]),\
  121.         "\n\n\t\tWhat is your mother's maiden name? ", "".join(detailDict["question_3"]))
  122.  
  123.  
  124. set_userName()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement