1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 16:35:17 +00:00

Can login user

This commit is contained in:
2020-05-24 16:35:54 +02:00
parent 6f6cd550ea
commit f0cf3202f4
9 changed files with 153 additions and 11 deletions

View File

@ -5,6 +5,8 @@
extern crate sha1;
use crate::data::error::{ResultBoxError, ExecError};
use rand::{thread_rng, Rng};
use rand::distributions::Alphanumeric;
/// Generate a new sha1 string
///
@ -44,4 +46,20 @@ pub fn crypt_pass(pass: &str) -> ResultBoxError<String> {
}
Ok(String::from_utf8(result.stdout)?)
}
/// Generate a random string of a given size
///
/// ```
/// use comunic_server::utils::crypt_utils::rand_str;
///
/// let size = 10;
/// let rand = rand_str(size);
/// assert_eq!(size, rand.len());
/// ```
pub fn rand_str(len: usize) -> String {
thread_rng()
.sample_iter(&Alphanumeric)
.take(len)
.collect()
}