rand utils no longer using payload User struct
This commit is contained in:
parent
8cbfa9520e
commit
b39a95f3a3
@ -1,5 +1,5 @@
|
||||
// This modules mainly deals with creating various types of random data
|
||||
use getrandom;
|
||||
use getrandom::getrandom;
|
||||
|
||||
pub fn newUserID() -> u64 {
|
||||
let mut buf = [0u8; 8];
|
||||
@ -9,19 +9,19 @@ pub fn newUserID() -> u64 {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn newKey() -> Option<String> { // Returns a random string which we later hash with bcrypt
|
||||
pub fn newKey() -> String { // Returns a random string which we later hash with bcrypt
|
||||
let mut raw_slice = [0u8; 32];
|
||||
if let Some(_ignored) = getrandom(raw_slice) {
|
||||
if let Ok(_ignored) = getrandom(&mut raw_slice) {
|
||||
let mut buf = String::new();
|
||||
for i in raw_slice {
|
||||
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);
|
||||
}
|
||||
Some(buf)
|
||||
buf
|
||||
}
|
||||
else {
|
||||
None
|
||||
"".into()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user