added the gigachad detector

This commit is contained in:
FantasyPvP
2023-09-27 22:50:28 +01:00
parent 067d780fdf
commit 49bc77e44a
9 changed files with 176 additions and 72 deletions
+36
View File
@@ -0,0 +1,36 @@
use lazy_static::lazy_static;
use alloc::sync::Arc;
use spin::Mutex;
use alloc::{vec, vec::Vec, string::String};
lazy_static!(
static ref AUTHENTICATOR: Arc<Mutex<Vec<User>>> = Arc::new(Mutex::new(vec![User::new(
String::from("fantasypvp"),
String::from("password")
)]));
);
pub struct User {
username: String,
pass_hash: u64,
}
impl User {
fn new(username: String, password: String) -> User {
let pass_hash = User::get_pass_hash(&password);
User { username, pass_hash }
}
fn get_pass_hash(pass: &String) -> u64 {
pass.bytes().fold(0u64, |b, a| a as u64 + b as u64)
}
pub fn is_authenticated(username: String, password: String) -> Option<bool> {
let auth = AUTHENTICATOR.lock();
let user = auth.iter().find(|x| x.username == username)?;
if User::get_pass_hash(&password) == user.pass_hash {
Some(true)
} else {
Some(false)
}
}
}
+2 -1
View File
@@ -6,4 +6,5 @@ pub mod memory;
pub mod render;
pub mod serial;
pub mod tasks;
pub mod sysinit;
pub mod sysinit;
pub mod authenticator;
+3
View File
@@ -71,6 +71,9 @@ pub struct Renderer {
pub sandbox: bool,
}
lazy_static! {
pub static ref RENDERER: Mutex<Renderer> = Mutex::new(Renderer {
col_pos: 0,
View File