cakephp / authentication

Authentication plugin for CakePHP. Can also be used in PSR7 based applications.
MIT License
117 stars 100 forks source link

Add forceLowercase option to PasswordIdentifier #560

Closed othercorey closed 2 years ago

othercorey commented 2 years ago

This allows case-insensitive usernames when the username is always forced to lowercase when storing in the db.

This can reduce the dependency on the UI to always send case-insensitive strings to the server.

ADmad commented 2 years ago

Lowercasing in PHp would be not needed if case insensitive db field is used. I would rather have users do that instead.

othercorey commented 2 years ago

Lowercasing in PHp would be not needed if case insensitive db field is used. I would rather have users do that instead.

This isn't a supported data type in postgres unfortunately. There are ways to do case-insensitive string compares, but I don't think it's standard.

othercorey commented 2 years ago

The alternative is a custom resolver just for usernames which is what I use.

ADmad commented 2 years ago

Wouldn't you have to lowercase case the db value too to ensure a match? Lowercasing the user provided value won't help if the value stored in db is not in lowercase (for Postgres).

markstory commented 2 years ago

Wouldn't you have to lowercase case the db value too to ensure a match? Lowercasing the user provided value won't help if the value stored in db is not in lowercase (for Postgres).

Yes, you would need to have entity setters or save logic to lowercase the fields.

ADmad commented 2 years ago

Yes, you would need to have entity setters or save logic to lowercase the fields.

I would hate it if an app/site did that :). For e.g. my GH username is mixed cased and that's what's shown/works everywhere (I haven't set any display name). But I can still login using lower cased version of my username.

ADmad commented 2 years ago

So I think the db should store the exact string user provided during account creation and the lowercasing of db value too should be done in query. So perhaps this option belongs in the Orm resolver?

othercorey commented 2 years ago

Ok, will stick with a specialized solution.

othercorey commented 2 years ago

So I think the db should store the exact string user provided during account creation and the lowercasing of db value too should be done in query. So perhaps this option belongs in the Orm resolver?

Yes, that's the optimal solution. I use a lowercase index to ensure unique case-insensitive email addresses.

I don't run into the display name issue you mentioned because username is email, but it's a good point.

dereuromark commented 2 years ago

Even Email some people prefer different casing for readability :) so should usually also not get lowercased maybe.