Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.52 KB | None | 0 0
  1. class AccountDetails:
  2.     def __init__(self):
  3.         self.error = ErrorHandling
  4.  
  5.     def get_email(self, length: int):
  6.         """
  7.        @length: Email length/Amount of characters in the email address.
  8.        :returns: A email address (A fake one.)
  9.        """
  10.         pass
  11.  
  12.     def get_birthday(self):
  13.         """
  14.        :returns: birthday: A randomly generated birthday.
  15.        get_birthday.year = the birthday year e.g (2019)
  16.        get_birthday.month = the birthday month e.g (09)
  17.        get_birthday.day = the birthday day e.g (23)
  18.        """
  19.         year = random.randrange(1990, 2000)
  20.         month = random.randrange(1, 12)
  21.         day = random.randrange(1, 27)
  22.         return year, month, day
  23.  
  24.     def main(self):
  25.         birthday = self.get_birthday()
  26.         print(f"{birthday.year}, {birthday.month}, {birthday.day}")
  27.  
  28.     def get_username(self, length: int):
  29.         """
  30.        @length: Username length/Amount of characters in the Username (Must be between 1 to 12 characters).
  31.        :returns: username | A randomly generated username.
  32.        """
  33.  
  34.         # Uses our customly made errors and raises an error based on the length.
  35.         try:
  36.             if length < 1:
  37.                 error = self.error.TooShortError
  38.                 raise error
  39.             elif length > 12:
  40.                 error = self.error.TooLongError
  41.                 raise error
  42.         except error as e:
  43.             length = 8
  44.             print(e.message)
  45.         finally:
  46.             """We don't have to do any checks here
  47.               because the length gets automatically set to a accepted length incase of any errors."""
  48.  
  49.             # Last digits is the ending of the username in order for the username to hopefully be available.
  50.             last_digits = random.randrange(1, 123)
  51.             username = ''.join(random.choices(string.ascii_lowercase, k=length)) + f"{last_digits}"
  52.  
  53.             # We have to check if the username is actually is 12 characters because we add X amount of digits at the end
  54.             length_username = int(len(username))
  55.  
  56.             if length_username > 12:
  57.                 """We subtract 12 from the username length and then remove X amount of characters, X representing the
  58.                remainder, if there is a remainder (which there only should be if there's more than 12 characters) """
  59.                 remainder = length_username - 12
  60.                 if remainder > 0:
  61.                     username = username[:-remainder]
  62.             print(f"Generated username: {username}")
  63.             return username
  64.  
  65.     def get_password(self, length: int):
  66.         """
  67.        @length: Password length/Amount of characters in the Password (Must be between 5 to 20 characters).
  68.        :returns: password | A randomly generated password.
  69.        """
  70.  
  71.         # Uses our customly made errors and raises an error based on the length.
  72.         try:
  73.             if length < 5:
  74.                 error = self.error.TooShortError
  75.                 raise error
  76.             elif length > 20:
  77.                 error = self.error.TooLongError
  78.                 raise error
  79.         except error as e:
  80.             length = 12
  81.             print(e.message)
  82.         finally:
  83.             """We don't have to do any checks here
  84.               because the length gets automatically set to a accepted length incase of any errors."""
  85.             password = ''.join(random.choices(string.ascii_uppercase + string.digits, k=length))
  86.             print(f"Generated password: {password}")
  87.             return password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement