Skip to content

Commit

Permalink
Merge pull request #72 from Ankitmohanty2/ankit
Browse files Browse the repository at this point in the history
unique password generator
  • Loading branch information
Ayu-hack authored Oct 4, 2024
2 parents ebaaeb5 + 82bb5b4 commit 9c2cf7a
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Password_Generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import random
import string
import secrets

def generate_password(length=16):
if length < 12:
raise ValueError("Password length should be at least 12 characters for enhanced security.")

lower = string.ascii_lowercase
upper = string.ascii_uppercase
digits = string.digits
special = "!@#$%^&*()_+-=[]{}|;:,.<>?"

all_chars = lower + upper + digits + special

while True:
password = ''.join(secrets.choice(all_chars) for _ in range(length))
if (any(c.islower() for c in password)
and any(c.isupper() for c in password)
and sum(c.isdigit() for c in password) >= 3
and sum(c in special for c in password) >= 2):
return password

if __name__ == "__main__":
try:
password_length = int(input("Enter desired password length (at least 12): "))
strong_password = generate_password(password_length)
print(f"Your generated password is: {strong_password}")
except ValueError as e:
print(f"Error: {e}")
59 changes: 59 additions & 0 deletions Password_Generator/Password_Generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import random
import string
import secrets

def generate_password(length=8):
if length < 8:
raise ValueError("Password length should be at least 8 characters for security.")

lower = string.ascii_lowercase
upper = string.ascii_uppercase
digits = string.digits
special = "!@#$%^&*()_+-=[]{}|;:,.<>?"

all_chars = lower + upper + digits + special

while True:
password = ''.join(secrets.choice(all_chars) for _ in range(length))
if (any(c.islower() for c in password)
and any(c.isupper() for c in password)
and sum(c.isdigit() for c in password) >= 2
and sum(c in special for c in password) >= 1):
return password

def strengthen_password(base_password):
if len(base_password) < 8:
raise ValueError("Base password should be at least 8 characters long.")

lower = string.ascii_lowercase
upper = string.ascii_uppercase
digits = string.digits
special = "!@#$%^&*()_+-=[]{}|;:,.<>?"

password = list(base_password)

if not any(c.islower() for c in password):
password.append(secrets.choice(lower))
if not any(c.isupper() for c in password):
password.append(secrets.choice(upper))
if sum(c.isdigit() for c in password) < 2:
password.extend(secrets.choice(digits) for _ in range(2 - sum(c.isdigit() for c in password)))
if sum(c in special for c in password) < 1:
password.append(secrets.choice(special))

random.shuffle(password)
return ''.join(password)

if __name__ == "__main__":
user_input = input("Enter desired password length (at least 8) or a base password: ")

try:
password_length = int(user_input)
strong_password = generate_password(password_length)
print(f"Your generated password is: {strong_password}")
except ValueError:
try:
strengthened_password = strengthen_password(user_input)
print(f"Your strengthened password is: {strengthened_password}")
except ValueError as e:
print(f"Error: {e}")
40 changes: 40 additions & 0 deletions Password_Generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Password Generator

A simple and secure password generator implemented in Python.

## Description

This Python script generates strong, random passwords. It can create passwords of a specified length or strengthen existing passwords to meet security criteria.

## Features

- Generate random passwords (minimum 8 characters)
- Strengthen existing passwords
- Ensures a mix of uppercase, lowercase, numbers, and special characters

## Requirements

- Python 3.6+

## Usage

Run the script:

python Password_Generator.py


Follow the prompts to either generate a new password or strengthen an existing one.

## Example

Enter desired password length (at least 8) or a base password: 12
Your generated password is: 3Kj$9pQ@mF2x


## Author

[Ankitmohanty2]

## License

This project is open source and available under the MIT License.

0 comments on commit 9c2cf7a

Please sign in to comment.