File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -108,14 +108,21 @@ def user_login_json():
108
108
Expects json-encoded form data
109
109
"""
110
110
111
+ def dummy_check ():
112
+ """Perform a fake password hash check to take as much time as a real one."""
113
+ pw_bytes = bytes ('password' , "utf8" )
114
+ check_password ('password' , pw_bytes )
115
+
111
116
try :
112
117
post_dict = json .loads (request .data )
113
118
username = post_dict ["username" ]
114
119
presentedpw = post_dict ["password" ]
115
120
except :
121
+ dummy_check () # Take the same time as with well-formed requests
116
122
return jsonify ("Bad credentials" ), 401
117
123
118
124
if not (isinstance (username , str ) and isinstance (presentedpw , str ) ):
125
+ dummy_check () # Take the same time as with well-formed requests
119
126
return jsonify ("Bad credentials" ), 401 # Don't give us ints, arrays, etc.
120
127
121
128
You can’t perform that action at this time.
0 commit comments