@@ -11,11 +11,7 @@ def new
11
11
end
12
12
13
13
def create
14
- # Check
15
- field = ( resource_params . keys . map ( &:to_sym ) & resource_class . authentication_keys ) . first
16
-
17
- @resource = nil
18
- if field
14
+ if field = ( resource_params . keys . map ( &:to_sym ) & resource_class . authentication_keys ) . first
19
15
q_value = get_case_insensitive_field_from_resource_params ( field )
20
16
21
17
@resource = find_resource ( field , q_value )
@@ -41,12 +37,7 @@ def create
41
37
render_create_error_not_confirmed
42
38
end
43
39
else
44
- # In order to avoid timing attacks in paranoid mode, we want the password hash to be
45
- # calculated even if no resource has been found. Devise's DatabaseAuthenticatable warden
46
- # strategy handles this case similarly:
47
- # https://github.com/heartcombo/devise/blob/main/lib/devise/strategies/database_authenticatable.rb
48
- resource_class . new . password = resource_params [ :password ] if Devise . paranoid
49
-
40
+ hash_password_in_paranoid_mode
50
41
render_create_error_bad_credentials
51
42
end
52
43
end
@@ -150,5 +141,13 @@ def create_and_assign_token
150
141
@resource . save!
151
142
end
152
143
end
144
+
145
+ def hash_password_in_paranoid_mode
146
+ # In order to avoid timing attacks in paranoid mode, we want the password hash to be
147
+ # calculated even if no resource has been found. Devise's DatabaseAuthenticatable warden
148
+ # strategy handles this case similarly:
149
+ # https://github.com/heartcombo/devise/blob/main/lib/devise/strategies/database_authenticatable.rb
150
+ resource_class . new . password = resource_params [ :password ] if Devise . paranoid
151
+ end
153
152
end
154
153
end
0 commit comments