Skip to main content

authenticate

Function authenticate 

Source
pub async fn authenticate<U>(
    username: &str,
    plaintext: &str,
) -> Result<U, AuthError>
where U: UserModel + for<'r> FromRow<'r, SqliteRow> + for<'r> FromRow<'r, PgRow> + HydrateRelated + Unpin,
Expand description

Verify a username + plaintext password against the user table for user model U. Returns the user on success; returns AuthError::InvalidCredentials for both “no such user” and “wrong password” (the same shape, so a caller can’t enumerate accounts).

The query uses U::TABLE for the table name. The WHERE clause filters on username = ? and is_active = 1 (the standard column name for the active flag). Custom models that store the active flag under a different column name should filter directly and call verify_password themselves.

Does not update last_login; that is the login-flow’s job once the HTTP layer is wired end-to-end.