Skip to content

Commit abadff2

Browse files
committed
refactor: login captcha
1 parent 3c5b38d commit abadff2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

apps/common/utils/common.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,17 @@ def group_by(list_source: List, key):
5454
return result
5555

5656

57-
CHAR_SET = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
57+
SAFE_CHAR_SET = (
58+
[chr(i) for i in range(65, 91) if chr(i) not in {'I', 'O'}] + # 大写字母 A-H, J-N, P-Z
59+
[chr(i) for i in range(97, 123) if chr(i) not in {'i', 'l', 'o'}] + # 小写字母 a-h, j-n, p-z
60+
[str(i) for i in range(10) if str(i) not in {'0', '1', '7'}] # 数字 2-6, 8-9
61+
)
5862

5963

60-
def get_random_chars(number=6):
61-
return "".join([CHAR_SET[random.randint(0, len(CHAR_SET) - 1)] for index in range(number)])
64+
def get_random_chars(number=4):
65+
if number <= 0:
66+
return ""
67+
return ''.join(random.choices(SAFE_CHAR_SET, k=number))
6268

6369

6470
def encryption(message: str):

0 commit comments

Comments
 (0)