]> git.amazingca.dev Git - autumn/ws/commitdiff
Include default, insecure hashing differentiation
authorAmazingca <autumn@amazingca.dev>
Thu, 2 Jul 2026 03:50:51 +0000 (21:50 -0600)
committerAmazingca <autumn@amazingca.dev>
Thu, 2 Jul 2026 03:50:51 +0000 (21:50 -0600)
src/main.rs

index ce58c79ba3af0076296da3e04a3058cf1bece189..9dc8a30591d2af355d2646ffb3afbef88eeeea4a 100644 (file)
@@ -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<String>) {
     --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<String>) {
                     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);
             }
         }
     }