new users no longer contain optional fields
only using completely necessary information
This commit is contained in:
parent
23166a9e99
commit
8cbfa9520e
@ -8,6 +8,7 @@
|
||||
#[derive(Serialize)]
|
||||
pub struct NewUserInfo {
|
||||
pub userid: u64, // userid which later will be discoverable via the
|
||||
pub key_hash: Option<String>,
|
||||
pub username: String,
|
||||
pub key: String,
|
||||
pub valid: bool
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
// This modules mainly deals with creating various types of random data
|
||||
use getrandom;
|
||||
|
||||
pub fn newUserID() -> u64 {
|
||||
let mut buf = [0u8; 8];
|
||||
@ -6,22 +7,21 @@ pub fn newUserID() -> u64 {
|
||||
Ok(_val) => {u64::from_ne_bytes(buf)}
|
||||
Err(_e) => {0} // if this really happens we're fucked anyway
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn newKey() -> String {
|
||||
let mut buf = [0u8; 32];
|
||||
getrandom::getrandom(&mut buf)?;
|
||||
let mut string = String::new();
|
||||
for i in buf.iter() {
|
||||
// if the value isn't in the proper range then we place it in the proper range
|
||||
// [33-126]
|
||||
if i < 33 {
|
||||
i += 33;
|
||||
pub fn newKey() -> Option<String> { // Returns a random string which we later hash with bcrypt
|
||||
let mut raw_slice = [0u8; 32];
|
||||
if let Some(_ignored) = getrandom(raw_slice) {
|
||||
let mut buf = String::new();
|
||||
for i in raw_slice {
|
||||
let mut cv: u8 = *i;
|
||||
if cv > 126 { cv %= 126; }
|
||||
if cv < 33 { cv += 34; }
|
||||
buf.push(cv as char);
|
||||
}
|
||||
else if i > 126 {
|
||||
i %= 126;
|
||||
Some(buf)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
string
|
||||
}
|
@ -1,42 +1,17 @@
|
||||
use crate::rand_utils::{newUserID, newKey};
|
||||
use chrono:Utc;
|
||||
use payload::NewUserInfo;
|
||||
use getrandom::getrandom;
|
||||
use bcrypt::{hash, DEFAULT_COST};
|
||||
|
||||
fn rand_string() -> Option<String> {
|
||||
// Returns a random string which we later hash with bcrypt
|
||||
let mut raw_slice = [0u8; 32];
|
||||
if let Some(_ignored) = getrandom(raw_slice) {
|
||||
let mut buf = String::new();
|
||||
for i in raw_slice {
|
||||
let mut cv: u8 = *i;
|
||||
if cv > 126 { cv %= 126; }
|
||||
if cv < 33 { cv += 34; }
|
||||
buf.push(cv as char);
|
||||
}
|
||||
Some(buf)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn rand_uid() -> u64 {
|
||||
let mut buf = [0u8;8];
|
||||
let _r = getrandom(&mut buf); // this basically never fails hehexd
|
||||
u64::from_ne_bytes(buf)
|
||||
}
|
||||
|
||||
// Returns a struct of payload::NewUserInfo
|
||||
pub fn createNewUser() -> NewUserInfo {
|
||||
let uid = rand_id();
|
||||
let uname = format!("User: {}", uid);
|
||||
let hashkey = bcrypt(rand_string(), DEFAULT_COST);
|
||||
// Fuck it
|
||||
let uid = newUserID();
|
||||
let uname = format!("User:#{}", uid);
|
||||
let rstring = newKey();
|
||||
NewUserInfo {
|
||||
userid: uid,
|
||||
username: uname,
|
||||
key_hash: hashkey,
|
||||
valid: true
|
||||
key: rstring,
|
||||
valid: true,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user