mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 16:35:17 +00:00
Can login user
This commit is contained in:
@ -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()
|
||||
}
|
Reference in New Issue
Block a user