From ca98939c4477ec9c0f873cea92819d14fe8db00e Mon Sep 17 00:00:00 2001 From: Amazingca Date: Wed, 1 Jul 2026 21:50:51 -0600 Subject: [PATCH] Include default, insecure hashing differentiation --- src/main.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index ce58c79..9dc8a30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use bcrypt::hash; +use bcrypt::{hash, verify}; use regex::Regex; use std::{env, net::TcpListener, process::exit, thread}; @@ -18,11 +18,14 @@ fn args_handler(conf: &mut ServerConfig, args: Vec) { --help: print this help message --ip: set the IP address to bind the server to --port: set the port for the server - --token: token used to authenticate" + --token: bcrypt hash used to authenticate + --insecure: allows for raw text to be passed as a passphrase, which is hashed by bcrypt" ); exit(0); } + let insecure_context = args.iter().any(|i| i == "--insecure"); + for item in args { if item.contains("--ip=") { conf.ip = item.replace("--ip=", ""); @@ -40,8 +43,22 @@ fn args_handler(conf: &mut ServerConfig, args: Vec) { exit(-1); }); } else if item.contains("--token=") { + let hash = if insecure_context { + let hash = hash(item.replace("--token=", ""), 10).unwrap(); + println!("[!] Insecure mode: Raw text hashed as {}", &hash); + hash + } else { + let hash = item.replace("--token=", ""); + match verify("", &hash) { + Ok(_) => hash, + Err(x) => { + println!("{}", x); + exit(-1); + } + } + }; unsafe { - env::set_var("token", hash(item.replace("--token=", ""), 10).unwrap()); + env::set_var("token", hash); } } } -- 2.54.0