|
1 | 1 | #!/usr/bin/env python |
2 | | -import re |
3 | | -import sys |
4 | | -import random |
| 2 | +import re, sys, random, termios, tty |
5 | 3 | from getpass import getpass |
6 | 4 |
|
7 | 5 | # ANSI escape codes for colors |
|
20 | 18 | } |
21 | 19 |
|
22 | 20 | COMMON_WORDS = { |
23 | | - 'adjectives': ['Happy', 'Clever', 'Swift', 'Brave', 'Bright'], |
| 21 | + 'adjectives': ['Happy', 'Clever', 'Swift', 'Brave', 'Bright', 'Cool'], |
24 | 22 | 'nouns': ['Tiger', 'River', 'Mountain', 'Storm', 'Star'], |
25 | 23 | 'numbers': ['365', '42', '777', '314', '999'], |
26 | 24 | 'separators': ['_', '.', '#', '*', '@'] |
|
33 | 31 | 'special': re.compile(r'[!@#$%^&*(),.?":{}|<>]') |
34 | 32 | } |
35 | 33 |
|
| 34 | +def passwd_enter(prompt_part, mask="x"): |
| 35 | + prompt = f"\nEnter the Password to {prompt_part}: " |
| 36 | + sys.stdout.write(prompt) |
| 37 | + sys.stdout.flush() |
| 38 | + password = "" |
| 39 | + fd = sys.stdin.fileno() |
| 40 | + old_settings = termios.tcgetattr(fd) |
| 41 | + try: |
| 42 | + tty.setraw(fd) |
| 43 | + while True: |
| 44 | + ch = sys.stdin.read(1) |
| 45 | + if ch in ('\r', '\n'): |
| 46 | + sys.stdout.write('\r\n') |
| 47 | + sys.stdout.flush() |
| 48 | + break |
| 49 | + elif ch == '\x7f': # backspace |
| 50 | + if password: |
| 51 | + password = password[:-1] |
| 52 | + sys.stdout.write('\b \b') |
| 53 | + sys.stdout.flush() |
| 54 | + else: |
| 55 | + password += ch |
| 56 | + sys.stdout.write(mask) |
| 57 | + sys.stdout.flush() |
| 58 | + finally: |
| 59 | + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) |
| 60 | + return password |
36 | 61 |
|
37 | 62 | def format_to_header( |
38 | 63 | msg: str, |
@@ -168,8 +193,9 @@ def suggest_better_password(password): |
168 | 193 |
|
169 | 194 | # Smart character substitutions (maintain readability) |
170 | 195 | smart_subs = { |
171 | | - 'a': '@', 'e': '3', 'i': '!', 'o': '0', 's': '$', |
172 | | - 'ate': '8', 'to': '2', 'for': '4' |
| 196 | + 'a': '@', 'e': '€', 'i': '!', 'o': '0', 's': '$', |
| 197 | + 'ate': '8', 'to': '2', 'for': '4', 'and': '&', |
| 198 | + 'b': 'be', 'u': 'you' |
173 | 199 | } |
174 | 200 |
|
175 | 201 | # Apply substitutions intelligently |
@@ -212,7 +238,7 @@ def input_handler(): |
212 | 238 | print("For enhanced security, your input will be hidden.") |
213 | 239 | print("Hence, you may not see the characters as you type.") |
214 | 240 | try: |
215 | | - password = getpass("\nEnter password to check: ") |
| 241 | + password = passwd_enter("check") |
216 | 242 | except KeyboardInterrupt: |
217 | 243 | print("\nExiting...") |
218 | 244 | sys.exit(0) |
|
0 commit comments