aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e8999d4..a05a1ac 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,8 +16,8 @@ extern {
#[wasm_bindgen]
-pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: bool) -> String {
- if len == 0 ||!lower && !upper && !number && !special {
+pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: bool, extended: bool) -> String {
+ if len == 0 || !lower && !upper && !number && !special {
return "".to_string();
}
@@ -25,6 +25,8 @@ pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: boo
let mut lower_charset: Vec<char> = String::from("abcdefghijklmnopqrstuvwxyz").chars().collect();
let mut number_charset: Vec<char> = String::from("1234567890").chars().collect();
let mut special_charset: Vec<char> = String::from("!@#$%^&*()+{}[]><:|+=;-.,'?_~\\/`\"").chars().collect();
+ let mut extended_charset: Vec<char> = String::from("®û´¢æ«æëàñîêáö½¬èñý¹áúóâªò×ä¸ÿ¦ù°º±¨åûïøí»§÷î¤ã¡òþ¿³óùçâüëíõôéðìö¶þ¾úý·êéãߣüèðµå¥õïà¼øäô©²¯çì").chars().collect();
+
let mut result: Vec<char> = Vec::new();
let mut rng = rand::thread_rng();
@@ -45,6 +47,10 @@ pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: boo
result.append(&mut special_charset);
}
+ if extended {
+ result.append(&mut extended_charset);
+ }
+
(0..len)
.map(|_| {
let idx = rng.gen_range(0..result.len());