mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	feat(users): add support to verify 2FA using recovery code (#4737)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		| @ -45,7 +45,7 @@ pub async fn check_totp_in_redis(state: &AppState, user_id: &str) -> UserResult< | ||||
|  | ||||
| pub async fn check_recovery_code_in_redis(state: &AppState, user_id: &str) -> UserResult<bool> { | ||||
|     let redis_conn = get_redis_connection(state)?; | ||||
|     let key = format!("{}{}", consts::user::REDIS_RECOVERY_CODES_PREFIX, user_id); | ||||
|     let key = format!("{}{}", consts::user::REDIS_RECOVERY_CODE_PREFIX, user_id); | ||||
|     redis_conn | ||||
|         .exists::<()>(&key) | ||||
|         .await | ||||
| @ -59,3 +59,16 @@ fn get_redis_connection(state: &AppState) -> UserResult<Arc<RedisConnectionPool> | ||||
|         .change_context(UserErrors::InternalServerError) | ||||
|         .attach_printable("Failed to get redis connection") | ||||
| } | ||||
|  | ||||
| pub async fn insert_recovery_code_in_redis(state: &AppState, user_id: &str) -> UserResult<()> { | ||||
|     let redis_conn = get_redis_connection(state)?; | ||||
|     let key = format!("{}{}", consts::user::REDIS_RECOVERY_CODE_PREFIX, user_id); | ||||
|     redis_conn | ||||
|         .set_key_with_expiry( | ||||
|             key.as_str(), | ||||
|             common_utils::date_time::now_unix_timestamp(), | ||||
|             state.conf.user.two_factor_auth_expiry_in_secs, | ||||
|         ) | ||||
|         .await | ||||
|         .change_context(UserErrors::InternalServerError) | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Apoorv Dixit
					Apoorv Dixit