Jump to content

Username sanitation mismatch?


Hani
 Share

Recommended Posts

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()[/b]

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...