Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not strip leading or trailing whitespaces in password fields #605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sbesson
Copy link
Member

@sbesson sbesson commented Jan 22, 2025

The default behavior of the CharField class in Django forms is to strip leading and trailing whitespaces from the input text - see https://docs.djangoproject.com/en/4.2/ref/forms/fields/#django.forms.CharField.strip.

For authentication, this means that a user with a password containing leading or trailing whitespace is currently unable to log in via OMERO.web.

This commit fixes the login form as well as the change password form to preserve leading/trailing whitespace in all passwords fields.

Two workflows should be tested for this change

  1. authentication workflow

    a. create a new user
    b. change its password using the OMERO CLI (omero user password) and set a value including a leading or trailing password
    c. log in via OMERO CLI using the new password should work and confirm the password has been set in the DB
    d. log in via OMERO.web using the new password should fail without this PR but succeed with this PR

  2. password change workflow

    a. create a new user
    b. change its password using the OMERO Web (my account or as an admin) and set a value including a leading or trailing password
    c. log in via OMERO CLI using the new password should fail without this PR and succeed with this PR
    d. log in via OMERO.web using the new password should succeed without this PR (as the whitespaces will be stripped from both forms) as well as with this PR

/cc @stick

The default behavior of the CharField class in Django forms is to strip
leading and trailing whitespaces from the input text - see
https://docs.djangoproject.com/en/4.2/ref/forms/fields/#django.forms.CharField.strip.

For authentication, this means that a user with a password containing
leading or trailing whitespace is currently unable to log in via
OMERO.web.

This commit fixes the login form as well as the change password form
to preserve leading/trailing passwords.
@sbesson sbesson changed the title Do not strip password leading or trailing whitespaces Do not strip leading or trailing whitespaces in password fields Jan 22, 2025
Copy link
Member

@knabar knabar left a comment

Choose a reason for hiding this comment

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

Confirmed that without this patch:

  • cannot set password with leading/trailing space
  • cannot log into web if password set with trailing space via CLI

With this patch, everything works as expected.

Copy link
Member

@will-moore will-moore left a comment

Choose a reason for hiding this comment

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

Both the auth and password changing workflows handled passwords with whitespace as expected. LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants