# How to authenticate with username and password

**URL:** <https://community.auth0.com/t/how-to-authenticate-with-username-and-password/96624>\
**Category:** Get Help\
**Tags:** custom-database-connections, connections\
**Created:** [December 16, 2022, 3:56pm UTC](https://community.auth0.com/t/how-to-authenticate-with-username-and-password/96624 "2022-12-16T15:56:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anish.subedi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anish.subedi/32/33385_2.png) [@anish.subedi](https://community.auth0.com/u/anish.subedi)\
**Post date:** [December 16, 2022, 3:56pm UTC](https://community.auth0.com/t/how-to-authenticate-with-username-and-password/96624/1 "2022-12-16T15:56:34Z")

</div>

Hi team,

I am using a custom database, where my database uses a username[not email] and password to authenticate the user. Now how can we pass the username in the login script? I am disabling import user so all the get and create script will execute accordingly

---

<div class="post-metadata">

**Author:** ![david\_wisecarver](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david_wisecarver/32/37472_2.png) [@david\_wisecarver](https://community.auth0.com/u/david_wisecarver)\
**Post date:** [December 21, 2022, 9:41pm UTC](https://community.auth0.com/t/how-to-authenticate-with-username-and-password/96624/4 "2022-12-21T21:41:32Z")

</div>

Hi @anish.subedi,

You should be able to use the `email` in the login script as either the email or username of a user, and then include the username in the profile returned. I should note that if you do decide to turn import mode on, these users will need a unique email address for their Auth0 profile as that is a requirement.

---

<div class="post-metadata">

**Author:** ![anish.subedi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anish.subedi/32/33385_2.png) [@anish.subedi](https://community.auth0.com/u/anish.subedi)\
**Post date:** [December 22, 2022, 2:31am UTC](https://community.auth0.com/t/how-to-authenticate-with-username-and-password/96624/5 "2022-12-22T02:31:17Z")

</div>

Hi @david_wisecarver ,

Thank you for your response. I just want username property in getuser script, login script within the script template you have provided.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/0/9/0913cb26822e2bb2edc46c30ed7c47642ffc5524.png)  
Because while triggering create operation it triggers the following script asynchronously. Now in get user I need to pass get used by any other user attribute[suppose I have a username in my external db] but the template doesnt contain that field. So how to catch that value within the get script  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/7/f/7f458a7d9d7c5cf05ab75f96acafab4878540790.png)

Yes, additional logic is necessary to add in the get user script, login script, but how to add that logic, auth0 has given us the template where only email can be used, and replacing and adding username parameter is not working here.

```auto
`function getUser(email, callback) {

```

// Send user identifier to external database API  
let options = {  
url: “[https://example.com/api/search-users](https://example.com/api/search-users)”,  
body: {  
email: email  
}  
};`

`````auto
````Preformatted text`

Please please need more details on the implementation.
`````

---

<div class="post-metadata">

**Author:** ![anish.subedi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anish.subedi/32/33385_2.png) [@anish.subedi](https://community.auth0.com/u/anish.subedi)\
**Post date:** [December 23, 2022, 5:49am UTC](https://community.auth0.com/t/how-to-authenticate-with-username-and-password/96624/6 "2022-12-23T05:49:51Z")

</div>

Hi @david_wisecarver ,

Actively waiting for your response.

---

<div class="post-metadata">

**Author:** ![david\_wisecarver](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david_wisecarver/32/37472_2.png) [@david\_wisecarver](https://community.auth0.com/u/david_wisecarver)\
**Post date:** [December 23, 2022, 11:21pm UTC](https://community.auth0.com/t/how-to-authenticate-with-username-and-password/96624/7 "2022-12-23T23:21:16Z")

</div>

Hi @anish.subedi,

If you are wanting to create new users with the `create` script, you will need to include a unique `email` for the user as well. If you have import mode off and Require Username enabled, the get\_user script will actually only use the `email`. We have a backlog item in to address that the get\_user script does not run again with a username, though we do not have an ETA for that at the moment. The workaround would be to use the `get_user` script to validate existing emails, but would only validate for existing username in the `create` script logic .

I also wanted to share this link to another community post that covers how your Custom DB scripts to be able to handle the `email` parameter being passed as either an email or a username: [Username does not work for custom mongodb connection](https://community.auth0.com/t/username-does-not-work-for-custom-mongodb-connection/57637)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 10, 2023, 12:15pm UTC](https://community.auth0.com/t/how-to-authenticate-with-username-and-password/96624/9 "2023-01-10T12:15:29Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [August 19, 2024, 3:31pm UTC](https://community.auth0.com/t/how-to-authenticate-with-username-and-password/96624/10 "2024-08-19T15:31:24Z")

</div>

Hi team!

Updating this topic with our latest solution that makes it possible to create an account with flexible identifiers → [Activate and Configure Attributes for Flexible Identifiers](https://auth0.com/docs/authenticate/database-connections/activate-and-configure-attributes-for-flexible-identifiers). You can select between Email, Phone, or Username as Identifiers for your database connection.

Thanks  
Dawid
