From: Amazingca Date: Thu, 2 Jul 2026 03:50:51 +0000 (-0600) Subject: Include default, insecure hashing differentiation X-Git-Url: http://git.amazingca.dev/?a=commitdiff_plain;h=ca98939c4477ec9c0f873cea92819d14fe8db00e;p=autumn%2Fws Include default, insecure hashing differentiation --- 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); } } }