3
votes

I have a DAO method which returns an Future Option, it is like this:

def authenticate(username: String, password: String): Future[Option[User]] = {

    val query = db.run(Users.filter(x => x.email === username && password.isBcrypted(x.password.toString())).result).map(_.headOption)
    query
  }

The problem is, password.isBcrypted(x.password.toString()), where I am trying to get value of x.password, but it is Rep[String], I tried to find how to get the value from Rep[T] but couldnt come up with a solution.

Is there a good way for this?


Solution

val query = db.run(Users.filter(_.email === username).result.map(_.headOption.filter(user => password.isBcrypted(user.password)))).map(_.headOption)
1

1 Answers

4
votes

You could check password after getting the result:

Users.filter(_.email === username).result.map(_.headOption.filter(user => password.isBcrypted(user.password)))