annotate python/generate_password.py @ 921:02b31a76e2c4

get DEST from command line
author Jeff Hammel <k0scist@gmail.com>
date Sun, 02 Jun 2024 16:35:01 -0700
parents 1b6f0650dabb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
871
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 import random
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 import string
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 import sys
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 pool = ''.join([string.ascii_letters,
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 string.digits,
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 string.punctuation])
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 contents = [(string.ascii_lowercase, 6),
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 (string.ascii_uppercase, 6),
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 (string.punctuation, 2)]
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 def password(length=16, pool=pool):
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 return ''.join(random.sample(pool, length))
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 def main(args=sys.argv[1:]):
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 """CLI"""
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 print(password())
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 if __name__ == '__main__':
1b6f0650dabb add script to generate passwords
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 main()