annotate python/generate_password.py @ 892:3387af3524dd

i3locker
author Jeff Hammel <k0scist@gmail.com>
date Tue, 01 Jun 2021 09:17:27 -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()