Jump to content


Photo

Username sanitation mismatch?

solved

  • Please log in to reply
4 replies to this topic

#1 Hani

Hani

    Full Member

  • Members
  • PipPipPip
  • 60 posts
  • 11

  • LocationSanta Barbara, CA

Posted 23 February 2012 - 01:04 PM

Using the $sanitizer->username() function on an email address returns the email address as is. This behavior is expected and correct according to the function's definition (in the cheat sheet), which is:

$sanitizer->username()
Sanitizes a value for a User name, meaning all characters except for these ASCII characters "a-zA-Z0-9-_.@" (not including the quotes) are removed. It also truncates the length to 50 characters.


However, when adding a user manually in PW, the name field shows a different formatting requirement:

Any combination of letters (a-z), numbers (0-9), dashes or underscores (no spaces).

So inputting email@domain.com into that field automatically changes it to email-domain.com. (The "." does in fact stay in there although its not part of the defined character requirement. No biggie.)

Shouldn't those two formats match?

Background info: The reason this came up is because I'm allowing folks to signup for my parish's website to access parishioner-only content on the site. However, instead of usernames, I'm relying on email addresses for registering and logging in (at least from their point of view). Since each user in PW requires a username, I'm making their username a sanitized version of their email address and was going to use the $sanitizer->username() function to automatically create their username based on their email address. But given the current sanitizing convention of $sanitizer->username(), I'll have to create a new sanitation function to accommodate.

Is there a reason for the discrepancy that I may have overlooked?

#2 Hani

Hani

    Full Member

  • Members
  • PipPipPip
  • 60 posts
  • 11

  • LocationSanta Barbara, CA

Posted 23 February 2012 - 01:29 PM

But given the current sanitizing convention of $sanitizer->username(), I'll have to create a new sanitation function to accommodate.


Ok, duh. I just have to use $sanitizer->pageName() instead. But the $sanitizer->username() function should behave just like $sanitizer->pageName(), no?

#3 ryan

ryan

    Hero Member

  • Administrators
  • 5,812 posts
  • 3144

  • LocationAtlanta, GA

Posted 23 February 2012 - 01:36 PM

In earlier versions of PW it was possible for usernames to be email addresses, but when users were switched to being pages, the usernames had to be compatible with page names. That pageName function you mentioned is the way to go, and username() should probably be deprecated or redirected to the pageName function, like you mentioned (something I need to do).

#4 Hani

Hani

    Full Member

  • Members
  • PipPipPip
  • 60 posts
  • 11

  • LocationSanta Barbara, CA

Posted 23 February 2012 - 01:40 PM

Okay - cool. Thanks, Ryan!

#5 adamkiss

adamkiss

    Master of the universe

  • Moderators
  • 1,078 posts
  • 289

Posted 29 February 2012 - 09:47 AM

I am all for deprecating things like this, so that available functions/methods (and documentation) aren't polluted with things not supported anymore (not complying with, or any word you might want to use).





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users