Guest User

Untitled

a guest
Dec 9th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. def menu():
  2. getmenuchoice = True
  3. while getmenuchoice == True:
  4. print("1. Check Password")
  5. print("2. Generate Password")
  6. print("3. Quit")
  7. menuchoice = str(input("Please input your choice: "))
  8. if menuchoice.isdigit():
  9. getmenuchoice = False
  10. else:
  11. print("Please input a valid choice")
  12. print("Hint: Just input the number of your choice")
  13. if menuchoice == "1":
  14. print("Running Checking Password Function")
  15. print("----------------------------------")
  16. checkingpassword()
  17. elif menuchoice == "2":
  18. print("Running Generate Password Function")
  19. print("----------------------------------")
  20. generatepassword()
  21. elif menuchoice == "3":
  22. quit()
  23. else:
  24. print("Please input a valid choice")
  25. menu()
  26. def checkingpassword():
  27. userpassword = input("Input your password: ")
  28. passwordlength = len(userpassword)
  29. allowedsymbols = ["!","$","%","^","&","*","(",")","-","_","=","+"]
  30. upperfound = False
  31. lowerfound = False
  32. digitfound = False
  33. symbolfound = False
  34.  
  35. import re
  36.  
  37. spaceError = re.search(r's',userpassword) is None
  38.  
  39. if spaceError != True:
  40. print("Invalid Password")
  41. menu()
  42.  
  43. if passwordlength < 8 or passwordlength > 24:
  44. print("Invalid Password")
  45. menu()
  46. else:
  47. for char in userpassword:
  48.  
  49. if char.isupper():
  50. upperfound = True
  51.  
  52. if char.islower():
  53. lowerfound = True
  54.  
  55. if char.isdigit():
  56. digitfound = True
  57.  
  58. if char in allowedsymbols:
  59. symbolfound = True
  60.  
  61. if upperfound == False and lowerfound == False and digitfound == False and symbolfound == False:
  62. print("Your password contains a character that is not allowed")
  63. menu()
  64. else:
  65. callscore = scoring(userpassword,upperfound,lowerfound,digitfound,allowedsymbols,passwordlength)
  66. return callscore
  67.  
  68. def scoring(userpassword,upperfound,lowerfound,digitfound,symbolfound,passwordlength):
  69. allowedrow1 = "qwertyuiop"
  70. allowedrow2 = "asdfghjkl"
  71. allowedrow3 = "zxcvbnm"
  72. points = 0
  73. counter = 0
  74. #adding points
  75. points += passwordlength
  76. print("+"+ str(passwordlength) + " for the length")
  77.  
  78. if upperfound == True:
  79. points += 5
  80. print("+5 for having uppercase")
  81. if lowerfound == True:
  82. points += 5
  83. print("+5 for having lowercase")
  84. if digitfound == True:
  85. points += 5
  86. print("+5 for having digits")
  87. if symbolfound == True:
  88. points += 5
  89. print("+5 for having symbols")
  90. if upperfound == True and lowerfound == True and digitfound == True and symbolfound == True:
  91. points += 10
  92. print("+10 for having everything")
  93.  
  94. #subtracting points
  95. if lowerfound == True and upperfound == False and digitfound == False and symbolfound == False:
  96. points -= 5
  97. print("-5 for only having lowercase")
  98. if upperfound == True and upperfound == False and digitfound == False and symbolfound == False:
  99. points -= 5
  100. print("-5 for only having uppercase")
  101. if digitfound == True and upperfound == False and lowerfound == False and symbolfound == False:
  102. points -= 5
  103. print("-5 for only having digits")
  104. if symbolfound == True and upperfound == False and lowerfound == False and digitfound == False:
  105. points -= 5
  106. print("+5 for only having symbols")
  107.  
  108. #subtracting three consecutive letters
  109. for position in range(0,len(userpassword)-2):
  110. posi = userpassword[position : position + 3]
  111. if posi.lower() in allowedrow1 :
  112. counter += 1
  113. if posi.lower() in allowedrow2 :
  114. counter += 1
  115. if posi.lower() in allowedrow3 :
  116. counter += 1
  117.  
  118. points = points - (counter * 5)
  119.  
  120. strength = passwordstrength(points)
  121. return strength
Add Comment
Please, Sign In to add comment