mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
When reading a password, if there is no tty, read from stdin instead.
This will allow one to pipe a password in: echo -e "secret123\secret123\n" | ipa password someuser
This commit is contained in:
@@ -393,14 +393,26 @@ class textui(backend.Backend):
|
||||
raw_input(self.encode(prompt))
|
||||
)
|
||||
|
||||
def read_password(self, label):
|
||||
"""
|
||||
Read a password either by prompting the user or from stdin depending
|
||||
on whether there is a tty.
|
||||
|
||||
This will let you do something like: echo -e "foo\nfoo\n" | ipa passwd
|
||||
"""
|
||||
if sys.stdin.isatty():
|
||||
return getpass.getpass(label)
|
||||
else:
|
||||
return sys.stdin.readline().strip()
|
||||
|
||||
def prompt_password(self, label):
|
||||
"""
|
||||
Prompt user for a password.
|
||||
"""
|
||||
try:
|
||||
while True:
|
||||
pw1 = getpass.getpass('%s: ' % label)
|
||||
pw2 = getpass.getpass(
|
||||
pw1 = self.read_password('%s: ' % label)
|
||||
pw2 = self.read_password(
|
||||
_('Enter %(label)s again to verify: ') % dict(label=label)
|
||||
)
|
||||
if pw1 == pw2:
|
||||
|
Reference in New Issue
Block a user