# Version 4 Authentication

**URL:** <https://discourse.cakephp.org/t/version-4-authentication/8815>\
**Category:** Need Help\
**Created:** [January 3, 2021, 11:23pm UTC](https://discourse.cakephp.org/t/version-4-authentication/8815 "2021-01-03T23:23:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterg](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@peterg](https://discourse.cakephp.org/u/peterg)\
**Post date:** [January 3, 2021, 11:23pm UTC](https://discourse.cakephp.org/t/version-4-authentication/8815/1 "2021-01-03T23:23:02Z")

</div>

I’m upgrading my app from V3 to V4. I have an issue with authentication.

All user personal data including email addresses are encrypted on the database.

On V3 at login I allow the user to input either a username or an email address into the username field. In the Users controller if the username field looks like an email address I go find the username from the email address and backfill the username field into the request, then let auth log him in.

In V4 the authentication is done before the controller gets to run. Can anyone suggest a way to get the same functionality to work on V4 please?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [January 3, 2021, 11:27pm UTC](https://discourse.cakephp.org/t/version-4-authentication/8815/2 "2021-01-03T23:27:56Z")

</div>

You were doing this in your `login` function? Just do it in a bit of middleware instead, which you load before the authentication middleware? Or write a custom authenticator?

---

<div class="post-metadata">

**Author:** ![peterg](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@peterg](https://discourse.cakephp.org/u/peterg)\
**Post date:** [January 4, 2021, 11:54am UTC](https://discourse.cakephp.org/t/version-4-authentication/8815/4 "2021-01-04T11:54:21Z")

</div>

Thanks for your response. I guess a custom authenticator might do it, any idea how I load that?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [January 4, 2021, 2:30pm UTC](https://discourse.cakephp.org/t/version-4-authentication/8815/5 "2021-01-04T14:30:08Z")

</div>

Sorry, it’s maybe actually a custom [resolver](https://book.cakephp.org/authentication/2/en/identifiers.html#writing-your-own-resolver) that you want?

---

<div class="post-metadata">

**Author:** ![peterg](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@peterg](https://discourse.cakephp.org/u/peterg)\
**Post date:** [January 5, 2021, 3:20pm UTC](https://discourse.cakephp.org/t/version-4-authentication/8815/6 "2021-01-05T15:20:41Z")

</div>

Hey thanks Zuluru, that has done it. My new custom resolver does exactly what I want. Thanks again.  
Happy New Year!
