@@ -57,10 +57,22 @@ const authServiceModule: Module = {
57
57
identifier,
58
58
password,
59
59
} : { identifier : string ; password : string } = req . body ;
60
+
61
+ const identifierRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ | ^ [ a - z A - Z 0 - 9 ] { 3 , 20 } $ / ;
62
+ const passwordRegex = / ^ (? = .* [ A - Z a - z ] ) (? = .* \d ) [ A - Z a - z \d ] { 8 , } $ / ;
63
+
60
64
if ( ! identifier || ! password ) {
61
65
return res . redirect ( '/login?err=missing_credentials' ) ;
62
66
}
63
67
68
+ if ( ! identifierRegex . test ( identifier ) ) {
69
+ return res . redirect ( '/login?err=invalid_identifier' ) ;
70
+ }
71
+
72
+ if ( ! passwordRegex . test ( password ) ) {
73
+ return res . redirect ( '/login?err=weak_password' ) ;
74
+ }
75
+
64
76
try {
65
77
const result = await handleLogin ( identifier , password ) ;
66
78
if ( result . success && result . user ) {
@@ -87,11 +99,30 @@ const authServiceModule: Module = {
87
99
router . post ( '/register' , async ( req : Request , res : Response ) => {
88
100
const { email, username, password } = req . body ;
89
101
102
+ const emailRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
103
+ const usernameRegex = / ^ [ a - z A - Z 0 - 9 ] { 3 , 20 } $ / ;
104
+ const passwordRegex = / ^ (? = .* [ A - Z a - z ] ) (? = .* \d ) [ A - Z a - z \d ] { 8 , } $ / ;
105
+
90
106
if ( ! email || ! username || ! password ) {
91
107
res . redirect ( '/register?err=missing_credentials' ) ;
92
108
return ;
93
109
}
94
110
111
+ if ( ! emailRegex . test ( email ) ) {
112
+ res . redirect ( '/register?err=invalid_email' ) ;
113
+ return ;
114
+ }
115
+
116
+ if ( ! usernameRegex . test ( username ) ) {
117
+ res . redirect ( '/register?err=invalid_username' ) ;
118
+ return ;
119
+ }
120
+
121
+ if ( ! passwordRegex . test ( password ) ) {
122
+ res . redirect ( '/register?err=weak_password' ) ;
123
+ return ;
124
+ }
125
+
95
126
try {
96
127
const existingUser = await prisma . users . findFirst ( {
97
128
where : { OR : [ { email } , { username } ] } ,
0 commit comments