Skip to content

Commit dc5f08b

Browse files
update email validation
regex email validation check
1 parent 00edd59 commit dc5f08b

1 file changed

Lines changed: 5 additions & 30 deletions

File tree

auth_backend/auth_plugins/email.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import hashlib
22
import logging
3+
import re
34
from typing import Annotated, Self
45

56
from annotated_types import MinLen
@@ -26,38 +27,12 @@
2627
settings = get_settings()
2728
logger = logging.getLogger(__name__)
2829

30+
EMAIL_CONST_REGEX = re.compile(
31+
r'^[a-zA-Z0-9_.+\-%]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$')
2932

3033
def check_email(v):
31-
restricted: set[str] = {
32-
'"',
33-
'#',
34-
'&',
35-
"'",
36-
'(',
37-
')',
38-
'*',
39-
',',
40-
'/',
41-
';',
42-
'<',
43-
'>',
44-
'?',
45-
'[',
46-
'\\',
47-
']',
48-
'^',
49-
'`',
50-
'{',
51-
'|',
52-
'}',
53-
'~',
54-
'\n',
55-
'\r',
56-
}
57-
if "@" not in v:
58-
raise ValueError()
59-
if set(v) & restricted:
60-
raise ValueError()
34+
if not EMAIL_REGEX.match(v):
35+
raise ValueError("Неверный формат email")
6136
return v
6237

6338

0 commit comments

Comments
 (0)