diff options
author | gabrielgio <gabriel.giovanini@pm.me> | 2022-03-25 18:55:37 +0100 |
---|---|---|
committer | gabrielgio <gabriel.giovanini@pm.me> | 2022-03-25 18:55:37 +0100 |
commit | 51b4460935bb04d26d368810aa5c330fb9bcccdd (patch) | |
tree | 1b4e72c4082bb1d3c363926cb0b058ff511da46a /src | |
parent | 60e47b9cb1127042c5567c2632936295fd210be5 (diff) | |
download | genpass-51b4460935bb04d26d368810aa5c330fb9bcccdd.tar.gz genpass-51b4460935bb04d26d368810aa5c330fb9bcccdd.tar.bz2 genpass-51b4460935bb04d26d368810aa5c330fb9bcccdd.zip |
ref: Add actual pass generator function
Modify `generate` function to actually generate usable.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -15,7 +15,17 @@ extern { } #[wasm_bindgen] -pub fn generate() -> String { - let num = rand::thread_rng().gen_range(0..100); - format!("{}", num) +pub fn generate(len: usize) -> String { + const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\ + abcdefghijklmnopqrstuvwxyz\ + 1234567890\ + !@#$%^&*()+{}[]"; + let mut rng = rand::thread_rng(); + + (0..len) + .map(|_| { + let idx = rng.gen_range(0..CHARSET.len()); + CHARSET[idx] as char + }) + .collect() } |