From bcf44a4c30f4a873dccc02f3e7398db574c49ba1 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Wed, 17 Aug 2022 16:55:15 +0200 Subject: [PATCH 1/2] Rename passwords.csv to users.csv --- src/usr/user.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/usr/user.rs b/src/usr/user.rs index ad91253be..08bf9cf9c 100644 --- a/src/usr/user.rs +++ b/src/usr/user.rs @@ -13,7 +13,7 @@ use core::str; use hmac::Hmac; use sha2::Sha256; -const PASSWORDS: &str = "/ini/passwords.csv"; +const USERS: &str = "/ini/users.csv"; const COMMANDS: [&str; 2] = ["create", "login"]; pub fn main(args: &[&str]) -> Result<(), ExitCode> { @@ -42,8 +42,8 @@ fn usage() -> Result<(), ExitCode> { // TODO: Add max number of attempts pub fn login(username: &str) -> Result<(), ExitCode> { - if !fs::exists(PASSWORDS) { - error!("Could not read '{}'", PASSWORDS); + if !fs::exists(USERS) { + error!("Could not read '{}'", USERS); return Err(ExitCode::Failure); } @@ -184,8 +184,8 @@ pub fn hash(password: &str) -> String { fn read_hashed_passwords() -> BTreeMap { let mut hashed_passwords = BTreeMap::new(); - if let Ok(contents) = api::fs::read_to_string(PASSWORDS) { - for line in contents.split('\n') { + if let Ok(csv) = api::fs::read_to_string(USERS) { + for line in csv.split('\n') { let mut rows = line.split(','); if let Some(username) = rows.next() { if let Some(hash) = rows.next() { @@ -211,5 +211,5 @@ fn save_hashed_password(username: &str, hash: &str) -> Result { csv.push_str(&format!("{},{}\n", u, h)); } - fs::write(PASSWORDS, csv.as_bytes()) + fs::write(USERS, csv.as_bytes()) } From 9fa892042d85e0c3b3e8b32cc9c47f7c7c42caf0 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Wed, 17 Aug 2022 16:55:37 +0200 Subject: [PATCH 2/2] Allow login with empty password --- src/usr/user.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/usr/user.rs b/src/usr/user.rs index 08bf9cf9c..60cecf7a5 100644 --- a/src/usr/user.rs +++ b/src/usr/user.rs @@ -15,6 +15,7 @@ use sha2::Sha256; const USERS: &str = "/ini/users.csv"; const COMMANDS: [&str; 2] = ["create", "login"]; +const DISABLE_EMPTY_PASSWORD: bool = false; pub fn main(args: &[&str]) -> Result<(), ExitCode> { if args.len() == 1 || !COMMANDS.contains(&args[1]) { @@ -98,7 +99,7 @@ pub fn create(username: &str) -> Result<(), ExitCode> { print!("\x1b[12h"); // Enable echo println!(); - if password.is_empty() { + if password.is_empty() && DISABLE_EMPTY_PASSWORD { return Err(ExitCode::Failure); }