-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_password_apple
More file actions
executable file
·56 lines (36 loc) · 1.1 KB
/
generate_password_apple
File metadata and controls
executable file
·56 lines (36 loc) · 1.1 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
"""Password generator inspired by Apple
Generates passwords that look like those suggested
by Apple's Password app.
The main purpose, compared to `generate_password`,
is to get passwords that are easy to enter using
a TV remote or similar input systems.
XXXXXX-YYYYYY-ZZZZZZ
"""
import random
import string
import sys, os
def generate_apple_password(include_numbers: bool, segment_length: int, segment_num: int) -> str:
allowed_chars = string.ascii_lowercase
allowed_chars += string.ascii_uppercase
if include_numbers:
allowed_chars += string.digits
pw = ""
for i in range(segment_num):
for j in range(segment_length):
pw += random.choice(allowed_chars)
# Segment separator
pw += "-"
pw = pw.rstrip("-")
return pw
def main():
if len(sys.argv) > 1:
print("Error: No command line options or arguments supported!", file=sys.stderr)
sys,exit(1)
# pw = generate_apple_password(True, 6, 4)
# pw = generate_apple_password(False, 6, 4)
pw = generate_apple_password(True, 5, 3)
# pw = generate_apple_password(False, 5, 3)
print(pw)
if __name__ == "__main__":
main()