Guest User

Sir's Password

a guest
Dec 18th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. fileTest =open("usernamepassword.txt", "a")#this creates the text file to store relevant information
  2.  
  3.  
  4.  
  5. print("What is your first name?")
  6. firstname = input()
  7.  
  8. print("What is your surname?")
  9. surname=input()
  10.  
  11. username=surname[0:3]+firstname[0]+str(len(surname))
  12. fileTest.write(username + "\n")
  13. #use + to not have spaces
  14.  
  15. #checks the password for validation
  16. import re
  17. print("Please enter a password: ")
  18. password=input()
  19.  
  20. x = True
  21. while x:
  22. if (len(password)<6 or len(password)>12):
  23. break
  24. elif not re.search("[a-z]",password):
  25. break
  26. elif not re.search("[0-9]",password):
  27. break
  28. elif not re.search("[A-Z]",password):
  29. break
  30. elif not re.search("[$#@]",password):
  31. break
  32. else:
  33. print("Valid Password")
  34. x=False
  35. break
  36.  
  37. if x!=password:
  38. password=input("Not a Valid Password. Please ensure that your password is between 6 and 12 characters and contains at least an Upper Case letter, a number or a special character. Please enter a new password:")
  39.  
  40. if x:
  41. print("Thank you for signing up, your user name is,", username,"and the password is", password)
  42.  
  43.  
  44.  
  45. fileTest.write(password)
  46.  
  47.  
  48. fileTest.close()
  49.  
  50.  
  51. file = open("usernamepassword.txt")
  52. text = file.readlines()
  53.  
  54.  
  55.  
  56.  
  57. print("Please confirm your username: ")
  58. username1=input()
  59.  
  60. if username1!=text[0]:
  61. print("This username does not exist")
  62.  
  63. while username1!=username:
  64. username1=input("Please try again:")
  65.  
  66. else:
  67. print("Thank you")
  68.  
  69. attempt=0
  70. flag=0
  71.  
  72.  
  73. while (attempt!=3):
  74. password1=input("Please confirm password:")
  75. if password1==password:
  76. flag=1
  77. break
  78. else:
  79. attempt=attempt+1
  80. if(attempt==3):
  81. print("You have reached the maximum number of attempts!")
  82.  
  83. while password1!=password:
  84. password1=input("Please try again:")
  85.  
  86. else:
  87. print("Thank you, your details have been saved and confirmed.")
Add Comment
Please, Sign In to add comment