Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Add option SECURITY_LOGIN_SHOW_USER_EXISTENCE to hide 'user does not … #802

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ Miscellaneous
the value of
``SECURITY_CONFIRMABLE`` is set to
``True``. Defaults to ``False``.
``SECURITY_LOGIN_SHOW_USER_EXISTENCE`` Specifies the login api whether to
show user does not exist message
``SECURITY_MSG_USER_DOES_NOT_EXIST``
or empty password message
``SECURITY_MSG_PASSWORD_NOT_SET``.
Defaults to ``True``.
``SECURITY_CONFIRM_SALT`` Specifies the salt value when
generating confirmation
links/tokens. Defaults to
Expand Down
1 change: 1 addition & 0 deletions flask_security/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
'CONFIRM_EMAIL_WITHIN': '5 days',
'RESET_PASSWORD_WITHIN': '5 days',
'LOGIN_WITHOUT_CONFIRMATION': False,
'LOGIN_SHOW_USER_EXISTENCE': True,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

'EMAIL_SENDER': LocalProxy(lambda: current_app.config.get(
'MAIL_DEFAULT_SENDER', 'no-reply@localhost'
)),
Expand Down
20 changes: 14 additions & 6 deletions flask_security/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,22 @@ def validate(self):
self.user = _datastore.get_user(self.email.data)

if self.user is None:
self.email.errors.append(get_message('USER_DOES_NOT_EXIST')[0])
# Reduce timing variation between existing and non-existung users
hash_password(self.password.data)
if current_app.extensions['security'].login_show_user_existence:
self.email.errors.append(get_message('USER_DOES_NOT_EXIST')[0])
else:
self.password.errors.append(get_message('INVALID_PASSWORD')[0])
# Reduce timing variation between existing and non-existung
# users
hash_password(self.password.data)
return False
if not self.user.password:
self.password.errors.append(get_message('PASSWORD_NOT_SET')[0])
# Reduce timing variation between existing and non-existung users
hash_password(self.password.data)
if current_app.extensions['security'].login_show_user_existence:
self.password.errors.append(get_message('PASSWORD_NOT_SET')[0])
else:
self.password.errors.append(get_message('INVALID_PASSWORD')[0])
# Reduce timing variation between existing and non-existung
# users
hash_password(self.password.data)
return False
if not self.user.verify_and_update_password(self.password.data):
self.password.errors.append(get_message('INVALID_PASSWORD')[0])
Expand Down