From fdf4f0bef902d60f3bbf59d12e117b8de192f998 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Wed, 11 May 2022 15:43:25 +0530 Subject: [PATCH] feat: implement password fetching for sqlx postgres --- db/db-sqlx-postgres/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/db/db-sqlx-postgres/src/lib.rs b/db/db-sqlx-postgres/src/lib.rs index 0d575e23..d8d086dd 100644 --- a/db/db-sqlx-postgres/src/lib.rs +++ b/db/db-sqlx-postgres/src/lib.rs @@ -188,6 +188,24 @@ impl MCDatabase for Database { .map_err(map_register_err)?; Ok(()) } + + /// get a user's password + async fn get_password(&self, username: &str) -> DBResult { + struct Password { + password: String, + } + + let rec = sqlx::query_as!( + Password, + r#"SELECT password FROM mcaptcha_users WHERE name = ($1)"#, + username, + ) + .fetch_one(&self.pool) + .await + .map_err(map_register_err)?; + + Ok(rec.password) + } } fn now_unix_time_stamp() -> i64 {