Remove password masking from admin password prompt

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 15:27:59 -05:00
parent 66142dcb3c
commit 73802ad96c

View File

@@ -19,7 +19,6 @@ import subprocess
import sys import sys
import termios import termios
import time import time
import tty
import urllib.error import urllib.error
import urllib.request import urllib.request
from base64 import b64encode from base64 import b64encode
@@ -93,44 +92,16 @@ def draw_box(lines: list, colour: str = C.CYN):
# ── Input helpers ───────────────────────────────────────────────────────────── # ── Input helpers ─────────────────────────────────────────────────────────────
def prompt(label: str, default: str = "", password: bool = False) -> str: def prompt(label: str, default: str = "") -> str:
display = f" {_c(C.CYN, label)}" display = f" {_c(C.CYN, label)}"
if default: if default:
display += f" {_c(C.DIM, f'[{default}]')}" display += f" {_c(C.DIM, f'[{default}]')}"
display += ": " display += ": "
if password: sys.stdout.write(display)
fd = sys.stdin.fileno() sys.stdout.flush()
old = termios.tcgetattr(fd) val = sys.stdin.readline().strip()
try: return val if val else default
tty.setraw(fd)
sys.stdout.write(display)
sys.stdout.flush()
chars = []
while True:
ch = sys.stdin.read(1)
if ch in ("\r", "\n"):
break
elif ch in ("\x7f", "\x08"):
if chars:
chars.pop()
sys.stdout.write("\b \b")
sys.stdout.flush()
elif ch == "\x03":
raise KeyboardInterrupt
else:
chars.append(ch)
sys.stdout.write("*")
sys.stdout.flush()
print()
return "".join(chars)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
else:
sys.stdout.write(display)
sys.stdout.flush()
val = sys.stdin.readline().strip()
return val if val else default
def prompt_ip(label: str) -> str: def prompt_ip(label: str) -> str:
@@ -155,7 +126,6 @@ def prompt_password() -> str:
while True: while True:
val = prompt( val = prompt(
"Admin password (BMC/chassis serial, e.g. MXE3000043CHA007)", "Admin password (BMC/chassis serial, e.g. MXE3000043CHA007)",
password=True,
) )
if val: if val:
return val return val