Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. import random
  2. class networkAccess:
  3. def __init__(self):
  4. self.password = self.def_pwd()
  5. print("Your default password: " + self.password)
  6. self.username = self.create_username()
  7. print("Your username: " + self.username)
  8. self.change_pwd()
  9. print("Your new password: " + self.password)
  10.  
  11.  
  12. def set_firstname(self, name):
  13. self.firstname = name
  14. def set_middlename(self, name):
  15. self.middlename = name
  16. def set_lastname(self, name):
  17. self.lastname = name
  18. def set_username(self, username):
  19. self.username = username
  20.  
  21.  
  22. def create_username(self):
  23.  
  24. first = raw_input("Enter your first name: ")
  25. self.set_firstname(first)
  26.  
  27. middle = raw_input("Enter your middle name: ")
  28. self.set_middlename(middle)
  29.  
  30. last = raw_input("Enter your last name: ")
  31. self.set_lastname(last)
  32.  
  33. new_username = self.firstname.lower()[0] + self.middlename.lower()[0] + self.lastname.lower()[0] + str(random.randint(100,999))
  34. self.set_username(new_username)
  35. return new_username
  36.  
  37.  
  38. def def_pwd(self):
  39. num_of_upper = random.randint(2,4)
  40. num_of_lower = random.randint(2,4)
  41. num_of_number = random.randint(2,4)
  42. num_of_symbol = random.randint(2,4)
  43.  
  44. pwd = ""
  45.  
  46. for i in range(num_of_upper):
  47. upper = chr(random.randint(65,90))
  48. pwd = pwd + upper
  49. for i in range(num_of_lower):
  50. lower = chr(random.randint(97,122))
  51. pwd = pwd + lower
  52. for i in range(num_of_number):
  53. num = chr(random.randint(48,57))
  54. pwd = pwd + num
  55. for i in range(num_of_symbol):
  56. symbol = chr(random.randint(58,64))
  57. pwd = pwd + symbol
  58. l = list(pwd)
  59. random.shuffle(l)
  60. pwd = ''.join(l)
  61.  
  62. return pwd
  63.  
  64. def change_pwd(self):
  65. password = raw_input("Enter your new password: ")
  66.  
  67.  
  68. numbers = 0
  69. symbols = 0
  70. upper = 0
  71. lower = 0
  72. for L in password:
  73. o = ord(L)
  74. if(o >= 48 and o <= 57):
  75. numbers += 1
  76. if((o >= 32 and o <= 47) or (o >= 58 and o <= 64) or (o >= 91 and o <= 96) or (o >= 123 and o <= 126)):
  77. symbols += 1
  78. if(o >= 65 and o <= 90):
  79. upper += 1
  80. if(o >= 97 and o <= 122):
  81. lower += 1
  82.  
  83.  
  84.  
  85. if(numbers < 1):
  86. print("***Password must contain at least one number***")
  87. return False
  88.  
  89. if(symbols < 1):
  90. print("***Password must contain at least one symbol***")
  91. return False
  92.  
  93. if(upper < 1):
  94. print("***Password must contain at least one uppercase letter***")
  95. return False
  96.  
  97. if(len(password) < 8):
  98. print("***Passoword must be at least 8 characters long***")
  99. return False
  100.  
  101. if(password == self.password):
  102. print("***Passoword can't be the same as the old one***")
  103. return False
  104.  
  105. if(self.firstname.lower() in password.lower() or self.lastname.lower() in password.lower):
  106. print("***Passoword can't contain your first nor your last name***")
  107.  
  108. self.password = password
  109. return True
  110.  
  111. network = networkAccess()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement