From 8f4e5f4bdcf0970bec8b38ce5bcd889b7ec9b6f2 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Wed, 24 Aug 2022 06:43:35 +0000 Subject: [PATCH] bug fixed --- src/main.rs | 1 + src/services/member_bank_account/service.rs | 29 +++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index c989e8a..cad02f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,6 +83,7 @@ async fn main() -> Result<(), Box> { connection_server_broker.clone(), queue_server_broker.clone(), pool.clone(), + password_salt.clone(), ); let member_bank_deposit_service = services::member_bank_deposit::service::Service::new( connection_server_broker.clone(), diff --git a/src/services/member_bank_account/service.rs b/src/services/member_bank_account/service.rs index 3c9c3d5..0528a05 100644 --- a/src/services/member_bank_account/service.rs +++ b/src/services/member_bank_account/service.rs @@ -14,29 +14,32 @@ use diesel::{ use prost::Message; /// -pub struct Service { +pub struct Service<'a> { connection_broker: nats::asynk::Connection, queue_broker: String, pool: Pool>, site_repository: repositories::site::repository::Repository, site_composition: compositions::site::composition::Composition, member_bank_account_repository: repositories::member_bank_account::repository::Repository, + argon2_config: argon2::Config<'a>, + password_salt: String, } -impl std::fmt::Debug for Service { +impl std::fmt::Debug for Service<'_> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { f.debug_struct("Service of service.member.service.identity") .finish() } } -impl Service { +impl Service<'_> { /// pub fn new( connection_broker: nats::asynk::Connection, queue_broker: String, pool: Pool>, - ) -> Service { + password_salt: String, + ) -> Service<'static> { Service { connection_broker, queue_broker, @@ -45,6 +48,8 @@ impl Service { site_composition: compositions::site::composition::Composition::new(), member_bank_account_repository: repositories::member_bank_account::repository::Repository::new(), + argon2_config: argon2::Config::default(), + password_salt, } } @@ -794,6 +799,19 @@ impl Service { }, }) })?; + let exchange_password_hash = argon2::hash_encoded( + request.exchange_password.as_bytes(), + self.password_salt.as_bytes(), + &self.argon2_config, + ) + .map_err(|e| { + bcr::error::rpc::Error::Server(bcr::error::rpc::Server { + code: bpr::protobuf::rpc::Error::SERVER_00, + message: format!("server {}", e), + data: None, + }) + })?; + let conn = self.pool.get().map_err(|e| { bcr::error::rpc::Error::Server(bcr::error::rpc::Server { @@ -803,13 +821,14 @@ impl Service { }) })?; + let _affected = self .member_bank_account_repository .update_exchange_password( &conn, id, &repositories::member_bank_account::models::ModifyMemberBankAccountForExchangePassword { - exchange_password: request.exchange_password, + exchange_password: exchange_password_hash, }, ) .map_err(|e| {