# User authenticator

**URL:** <https://forums.kodeco.com/t/user-authenticator/180443>\
**Category:** Server Side Swift with Vapor\
**Created:** [October 27, 2022, 9:24am UTC](https://forums.kodeco.com/t/user-authenticator/180443 "2022-10-27T09:24:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kim/32/105896_2.png) [@kim](https://forums.kodeco.com/u/kim)\
**Post date:** [October 27, 2022, 9:24am UTC](https://forums.kodeco.com/t/user-authenticator/180443/1 "2022-10-27T09:24:51Z")

</div>

I created a user table with a username, email, password. username and email are unique, Users can log in using their username or email.

when use ModelAuthenticatable, the `usernameKey` mapping a field, either username or email. How do I make it map two keys?

```auto
extension User: ModelAuthenticatable {
   // username & email 
  static let usernameKey = \User.$username
  static let passwordHashKey = \User.$password

  func verify(password: String) throws -> Bool {
    try Bcrypt.verify(password, created: self.password)
  }
}

```

I created a separate authenticator, get basic.username, query the database, username and email which match, and then verify whether the password is correct.

 ![Screen Shot 2022-10-27 at 17.02.17](https://files.chunter.kodeco.com/original/3X/d/b/dbb2b57fc4c81149ae7b110426a38ebe1a645b7b.png)  
 ![Screen Shot 2022-10-27 at 17.03.27](https://files.chunter.kodeco.com/original/3X/8/f/8ff8d6008ebe42afa3c8369e34b3c1cfaa610646.png)

how to fix the error ? 😂 😂 😅 😅

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [October 27, 2022, 11:12am UTC](https://forums.kodeco.com/t/user-authenticator/180443/2 "2022-10-27T11:12:53Z")

</div>

You’re going about it the right way with a custom authenticator where you can do an OR query. Do you have Fluent imported in that file to be able to see the filter functions?

---

<div class="post-metadata">

**Author:** ![kim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kim/32/105896_2.png) [@kim](https://forums.kodeco.com/u/kim)\
**Post date:** [October 28, 2022, 1:01am UTC](https://forums.kodeco.com/t/user-authenticator/180443/3 "2022-10-28T01:01:55Z")

</div>

😂 I didn’t import fluent.  
thanks
