/
password-generator.py
61 lines (51 loc) · 2.27 KB
/
password-generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
This Python program generates a secure, NIST-compliant password based on user preferences for length,
inclusion of uppercase letters, numbers, and special characters. It ensures the generated password meets
a minimum length of 12 characters, as recommended for machine-generated passwords, and includes a mix of
character types to enhance complexity and security. The program also evaluates the strength of the generated
password, categorizing it as 'Weak', 'Moderate', 'Strong', or 'Very Strong' based on its length, diversity,
and uniqueness of characters. The final password is automatically copied to the clipboard for convenient use.
"""
import secrets
import string
import pyperclip
def generate_nist_compliant_password(length=12, use_uppercase=True, use_numbers=True, use_special_chars=True):
if length < 12:
print("Increasing password length to meet NIST minimum standards.")
length = 12
char_set = string.ascii_lowercase
if use_uppercase:
char_set += string.ascii_uppercase
if use_numbers:
char_set += string.digits
if use_special_chars:
char_set += string.punctuation
while True:
password = ''.join(secrets.choice(char_set) for _ in range(length))
if (not use_uppercase or any(char.isupper() for char in password)) and \
(not use_numbers or any(char.isdigit() for char in password)) and \
(not use_special_chars or any(char in string.punctuation for char in password)):
break
return password
def password_strength(password):
strength = ['Weak', 'Moderate', 'Strong', 'Very Strong']
score = 0
if len(password) >= 8:
score += 1
if any(char.isdigit() for char in password):
score += 1
if any(char in string.punctuation for char in password):
score += 1
if len(set(password)) > len(password) / 2:
score += 1
score = min(score, len(strength) - 1)
return strength[score]
length = 12
use_uppercase = True
use_numbers = True
use_special_chars = True
password = generate_nist_compliant_password(length, use_uppercase, use_numbers, use_special_chars)
strength = password_strength(password)
print(f"Generated Password: {password} (Strength: {strength})")
pyperclip.copy(password)
print("Password copied to clipboard.")