mariang_09

Untitled

Nov 10th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.17 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.     print("\n\t----Confirm your password")
  49.     confirmPassword = input("\n\t\tConfirmation: ")
  50.     if confirmPassword == userPassword:
  51.         print("\n\t----Your password was saved.")
  52.         user_login(userName, userPassword)
  53.     else:
  54.         print("\n\t----Your passwords don't match.")
  55.         time.sleep(1)
  56.         set_userPassword()
  57.  
  58. def user_login(userName, userPassword):
  59.     print("=" * 75)
  60.     tries = 0
  61.    
  62.     for tries in range(0, 2):
  63.  
  64.         loginUsername = input("\n\t\tEnter your username: ")
  65.         loginPassword = input("\n\t\tEnter your password: ")
  66.  
  67.         if loginPassword == userPassword and loginUsername == userName:
  68.             time.sleep(0.5)
  69.             detail_registration()
  70.  
  71.         else:
  72.             print("\n\t----Username or password wrong, check again")
  73.             tries +=1
  74.             if tries == 2:
  75.                 print("\n\t----Your account has been blocked. You can recover your password by answering one of the available security questions")
  76.                 security_questions(tries)
  77.  
  78. def detail_registration():
  79.     global userName, userQuestions, userPassword
  80.    
  81.     print("=" * 75)
  82.     print("\t----Welcome\n")
  83.  
  84.     detailDict = {
  85.         "username": userName,
  86.         "password": userPassword,
  87.         "question_1 ": userQuestions[0],
  88.         "question_2 ": userQuestions[1],
  89.         "question_3 ": userQuestions[2]
  90.                 }
  91.  
  92.     print("\t\tUsername: ", "".join(detailDict["username"]),\
  93.         "\n\n\t\tPassword: ", "".join(detailDict["password"]),\
  94.         "\n\n\t\tWhat is the title of your favourite movie? ", "".join(detailDict["question_1"]),\
  95.         "\n\n\t\tWho is your favourite artist? ", "".join(detailDict["question_2"]),\
  96.         "\n\n\t\tWhat is your mother's maiden name? ", "".join(detailDict["question_3"]))
  97.  
  98. def security_questions(tries):
  99.     global secQuestions, ansQuestions
  100.  
  101.     print("=" * 75)
  102.    
  103.     secNo = random.randint(1, 3)
  104.  
  105.     for i in range(1, 3):
  106.         if secNo == i:
  107.             print(secQuestions[i])
  108.             checkQuestion = input("Answer: ")
  109.  
  110.             if checkQuestion == ansQuestions:
  111.                 print("\n\t----Welcome")
  112.                 detail_registration()
  113.             else:
  114.                 print("\n\t----Your account has been blocked, call the customer service to retreive it.")
  115.  
  116. set_userName()
Add Comment
Please, Sign In to add comment