-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathaskpass
More file actions
executable file
·35 lines (27 loc) · 759 Bytes
/
askpass
File metadata and controls
executable file
·35 lines (27 loc) · 759 Bytes
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
#!/usr/bin/env python3
"""
Prompt the user for a password and print the result on stdout.
The password prompt goes to stderr. Input is read from stdin and terminated by
a newline. The result is written with no newline to stdout.
"""
import getpass
import optparse
import sys
p = optparse.OptionParser(usage='usage: %prog [PROMPT]' + __doc__.rstrip('\n'))
p.add_option('-n', '--newline', help='print trailing newline',
action='store_true')
opts, args = p.parse_args()
if args:
prompt = ' '.join(args)
else:
prompt = 'Password: '
out_stream = sys.stdout
try:
pw = getpass.getpass(prompt)
except EOFError:
sys.exit(1)
except KeyboardInterrupt:
sys.exit(2)
out_stream.write(pw)
if opts.newline:
out_stream.write('\n')