// This modules mainly deals with creating various types of random data use getrandom::getrandom; pub fn new_user_id() -> u64 { let mut buf = [0u8; 8]; match getrandom::getrandom(&mut buf) { // honestly if this fails idk wtf you want Ok(_val) => {u64::from_ne_bytes(buf)} Err(_e) => {0} // if this really happens we're fucked anyway } } pub fn new_key() -> String { // Returns a random string which we later hash with bcrypt let mut raw_slice = [0u8; 32]; if let Ok(_ignored) = getrandom(&mut raw_slice) { let mut buf = String::new(); for i in raw_slice.iter() { let mut cv: u8 = *i; if cv > 126 { cv %= 126; } if cv < 33 { cv += 34; } buf.push(cv as char); } buf } else { "".into() } }