1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use rand::{thread_rng, Rng};
pub fn number(bound: u64) -> u64 {
return thread_rng().next_u64() % bound;
}
pub fn bytes(length: usize) -> Vec<u8> {
let mut vec: Vec<u8> = Vec::new();
if length > 2048 {
return vec;
}
let mut random_data = [0u8; 2048];
thread_rng().fill_bytes(&mut random_data);
for i in 0..length {
vec.push(random_data[i]);
}
return vec;
}
pub mod passwd {
use bcrypt::{self, DEFAULT_COST};
pub fn create(pw: &str) -> Option<String> {
Some(bcrypt::hash(pw, DEFAULT_COST).ok()?)
}
pub fn verify(pw: &str, hash: &str) -> Option<bool> {
bcrypt::verify(pw, hash).ok()
}
}