-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from Ankitmohanty2/ankit
unique password generator
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |