Password Generator

In this lab, you will create a Python function named generate_password. This function is designed to generate strong, random passwords based on specified criteria. The password will consist of a mix of letters, numbers, and symbols. You need to ensure that the counts of each character type (letters, numbers, symbols) are taken as parameters, with default values of 2 for each and length parameter with the default value of 6.

Function Requirements:

  • The function should be named generate_password.
  • It should take four parameters: length (total length of the password), letters_count, numbers_count, and symbols_count.
  • If letters_count, numbers_count, or symbols_count are not specified, they should default to 2.
  • The function should return a randomly generated password string with the specified mix of characters.
  • The function should raise an ValueError in the length passed is less than the sum of letters, numbers and symbols together

Examples:

  1. Example 1:

    • Input: generate_password(length=8, letters_count=3, numbers_count=3, symbols_count=2)
    • Output: A random password of 8 characters, with 3 letters, 3 numbers, and 2 symbols. Example: a2#b4c5?
  2. Example 2:

    • Input: generate_password()
    • Output: A random password of 6 characters, using the default count of 2 for letters, numbers, and symbols. Example: 1d$2e#
  3. Example 3:

    • Input: generate_password(length=6, letters_count=3, numbers_count=3, symbols_count=2)
    • Output: ValueError

Remember to test your function thoroughly to ensure it meets the criteria specified in the challenges. Good luck!

TIP: You can make use of random and string modules to write the function easily

Adding your container request
Getting your dedicated container
Connecting to your container
Setting up your editor
Finalizing your playground
TerminalEditorBrowser