git clone https://github.com/injamul2k24/password_generator.git-
Navigate to the project directory:
cd password_generator -
Run the script:
python password_generator.py
-
Follow the prompts to generate your password.
$ python password_generator.py
How long password do you want to generate? 12
Include special characters? Yes/No: Yes
Include numbers? Yes/No: Yes
Generated Password: aB!9zL@3xN2pHere is the code for the password generator:
import random
string_char = 'abcdefghijklmnopqrstuvwxyz'
string_num = '0123456789'
special_char = '~!@#$%^&*()'
def GeneratePassword(length, use_special_chars, use_numbers):
"""Generates a random password based on user preferences."""
password = ''
for _ in range(length-2):
password += random.choice(string_char)
if use_numbers:
password += random.choice(string_num)
else:
password += random.choice(string_char)
if use_special_chars:
password += random.choice(special_char)
else:
password += random.choice(string_char)
return password
length = int(input("How long password do you want to generate? "))
use_special_chars = input("Include special characters? Yes/No: ").lower() == 'yes'
use_numbers = input("Include numbers? Yes/No: ").lower() == 'yes'
generated_password = GeneratePassword(length, use_special_chars, use_numbers)
print("\nGenerated Password:", generated_password)Feel free to contribute to this project by making suggestions or adding new features. Your feedback is welcome!