From b75ba216d1020212662f870306ebbeaf16e260fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Thu, 13 Sep 2018 23:04:52 +0200 Subject: [PATCH] Return default prelogin values when the user doesn't exist --- src/api/core/accounts.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index 6127be0e..78e08ba8 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -320,20 +320,22 @@ struct PreloginData { fn prelogin(data: JsonUpcase, conn: DbConn) -> JsonResult { let data: PreloginData = data.into_inner().data; - match User::find_by_mail(&data.Email, &conn) { + const KDF_TYPE_DEFAULT: i32 = 0; // PBKDF2: 0 + const KDF_ITER_DEFAULT: i32 = 5_000; + + let (kdf_type, kdf_iter) = match User::find_by_mail(&data.Email, &conn) { Some(user) => { - let kdf_type = 0; // PBKDF2: 0 - let _server_iter = user.password_iterations; - let client_iter = 5000; // TODO: Make iterations user configurable - + let client_iter = KDF_ITER_DEFAULT; // TODO: Make iterations user configurable - Ok(Json(json!({ - "Kdf": kdf_type, - "KdfIterations": client_iter - }))) + (KDF_TYPE_DEFAULT, client_iter) }, - None => err!("Invalid user"), - } + None => (KDF_TYPE_DEFAULT, KDF_ITER_DEFAULT), // Return default values when no user + }; + + Ok(Json(json!({ + "Kdf": kdf_type, + "KdfIterations": kdf_iter + }))) }