Add users authentication routes
This commit is contained in:
6
matrixgw_backend/src/utils/crypt_utils.rs
Normal file
6
matrixgw_backend/src/utils/crypt_utils.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
/// Compute SHA256sum of a given string
|
||||
pub fn sha256str(input: &str) -> String {
|
||||
hex::encode(Sha256::digest(input.as_bytes()))
|
||||
}
|
||||
3
matrixgw_backend/src/utils/mod.rs
Normal file
3
matrixgw_backend/src/utils/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod crypt_utils;
|
||||
pub mod rand_utils;
|
||||
pub mod time_utils;
|
||||
6
matrixgw_backend/src/utils/rand_utils.rs
Normal file
6
matrixgw_backend/src/utils/rand_utils.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use rand::distr::{Alphanumeric, SampleString};
|
||||
|
||||
/// Generate a random string of a given length
|
||||
pub fn rand_string(len: usize) -> String {
|
||||
Alphanumeric.sample_string(&mut rand::rng(), len)
|
||||
}
|
||||
9
matrixgw_backend/src/utils/time_utils.rs
Normal file
9
matrixgw_backend/src/utils/time_utils.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
/// Get the current time since epoch
|
||||
pub fn time_secs() -> u64 {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs()
|
||||
}
|
||||
Reference in New Issue
Block a user