feat: random tokens, sessions, guest usernames and device ids

This commit is contained in:
timokoesters 2020-04-06 22:57:58 +02:00
parent 64223b8812
commit ddcd423e6f
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
4 changed files with 38 additions and 13 deletions

View file

@ -1,3 +1,4 @@
use rand::prelude::*;
use std::{
convert::TryInto,
time::{SystemTime, UNIX_EPOCH},
@ -32,3 +33,10 @@ pub fn u64_from_bytes(bytes: &[u8]) -> u64 {
pub fn string_from_bytes(bytes: &[u8]) -> String {
String::from_utf8(bytes.to_vec()).expect("bytes are valid utf8")
}
pub fn random_string(length: usize) -> String {
thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(length)
.collect()
}