htpasswd: create tmp file before password asking

This commit is contained in:
Devaev Maxim 2019-02-10 04:55:25 +03:00
parent 06a0b77e35
commit ca90f39687

View File

@ -55,13 +55,13 @@ def _cmd_list(config: Section, _: argparse.Namespace) -> None:
def _cmd_set(config: Section, options: argparse.Namespace) -> None:
if options.read_stdin:
passwd = input()
else:
passwd = getpass.getpass("Password: ", stream=sys.stderr)
if getpass.getpass("Repeat: ", stream=sys.stderr) != passwd:
raise SystemExit("Sorry, passwords do not match")
with _get_htpasswd_for_write(config) as htpasswd:
if options.read_stdin:
passwd = input()
else:
passwd = getpass.getpass("Password: ", stream=sys.stderr)
if getpass.getpass("Repeat: ", stream=sys.stderr) != passwd:
raise SystemExit("Sorry, passwords do not match")
htpasswd.set_password(options.user, passwd)