@@ -142,38 +142,35 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
142142 raise ValidationError ("Failed to authenticate." )
143143 self .pre_user = pre_user
144144
145+ # Password check
146+ if current_stage .password_stage :
147+ password = attrs .get ("password" , None )
148+ if not password :
149+ self .stage .logger .warning ("Password not set for ident+auth attempt" )
150+ try :
151+ with start_span (
152+ op = "authentik.stages.identification.authenticate" ,
153+ name = "User authenticate call (combo stage)" ,
154+ ):
155+ user = authenticate (
156+ self .stage .request ,
157+ current_stage .password_stage .backends ,
158+ current_stage ,
159+ username = self .pre_user .username ,
160+ password = password ,
161+ )
162+ if not user :
163+ raise ValidationError ("Failed to authenticate." )
164+ self .pre_user = user
165+ except PermissionDenied as exc :
166+ raise ValidationError (str (exc )) from exc
167+
145168 # Captcha check
146169 if captcha_stage := current_stage .captcha_stage :
147170 captcha_token = attrs .get ("captcha_token" , None )
148171 if not captcha_token :
149172 self .stage .logger .warning ("Token not set for captcha attempt" )
150173 verify_captcha_token (captcha_stage , captcha_token , client_ip )
151-
152- # Password check
153- if not current_stage .password_stage :
154- # No password stage select, don't validate the password
155- return attrs
156-
157- password = attrs .get ("password" , None )
158- if not password :
159- self .stage .logger .warning ("Password not set for ident+auth attempt" )
160- try :
161- with start_span (
162- op = "authentik.stages.identification.authenticate" ,
163- name = "User authenticate call (combo stage)" ,
164- ):
165- user = authenticate (
166- self .stage .request ,
167- current_stage .password_stage .backends ,
168- current_stage ,
169- username = self .pre_user .username ,
170- password = password ,
171- )
172- if not user :
173- raise ValidationError ("Failed to authenticate." )
174- self .pre_user = user
175- except PermissionDenied as exc :
176- raise ValidationError (str (exc )) from exc
177174 return attrs
178175
179176
0 commit comments