diff --git a/doc/src/references/include/Token Generation (token_gen.nvgt)/!token_gen.md b/doc/src/references/include/Token Generation (token_gen.nvgt)/!token_gen.md index c2f59cd9..0925fc9f 100644 --- a/doc/src/references/include/Token Generation (token_gen.nvgt)/!token_gen.md +++ b/doc/src/references/include/Token Generation (token_gen.nvgt)/!token_gen.md @@ -1,2 +1,2 @@ # Token generation include -Allows you to easily generate random strings of characters of any length in a given mode. +Allows you to easily generate random strings of characters of any length in a given mode, and possibly custom function if you want to generate only certain characters. diff --git a/doc/src/references/include/Token Generation (token_gen.nvgt)/Enums/token_gen_flag.md b/doc/src/references/include/Token Generation (token_gen.nvgt)/Enums/token_gen_flag.md index 0c26fdf0..e8c19161 100644 --- a/doc/src/references/include/Token Generation (token_gen.nvgt)/Enums/token_gen_flag.md +++ b/doc/src/references/include/Token Generation (token_gen.nvgt)/Enums/token_gen_flag.md @@ -1,5 +1,5 @@ # token_gen_flag -This enum holds various constants that can be passed to the mode parameter in order to change how tokens are generated. +This enum holds various constants that can be passed to the mode parameter in order to change how tokens are generated in `generate_token` function. * token_gen_flag_all: Uses all characters, numbers and symbols, see below. * token_gen_flag_characters: Uses only characters, a-z, A-Z diff --git a/doc/src/references/include/Token Generation (token_gen.nvgt)/Functions/generate_token.nvgt b/doc/src/references/include/Token Generation (token_gen.nvgt)/Functions/!generate_token.nvgt similarity index 77% rename from doc/src/references/include/Token Generation (token_gen.nvgt)/Functions/generate_token.nvgt rename to doc/src/references/include/Token Generation (token_gen.nvgt)/Functions/!generate_token.nvgt index 66924de1..9ca22672 100644 --- a/doc/src/references/include/Token Generation (token_gen.nvgt)/Functions/generate_token.nvgt +++ b/doc/src/references/include/Token Generation (token_gen.nvgt)/Functions/!generate_token.nvgt @@ -7,7 +7,7 @@ ## returns: String: a random token depending on the mode. ## Remarks: - The characters used to generate the token will depend on the mode you set. See `token_gen_flags` enum constants. + This function uses `generate_custom_token` function to generate. The characters used to generate the token will depend on the mode you set. See `token_gen_flags` enum constants. */ // Example: diff --git a/doc/src/references/include/Token Generation (token_gen.nvgt)/Functions/generate_custom_token.nvgt b/doc/src/references/include/Token Generation (token_gen.nvgt)/Functions/generate_custom_token.nvgt new file mode 100644 index 00000000..9d3e769e --- /dev/null +++ b/doc/src/references/include/Token Generation (token_gen.nvgt)/Functions/generate_custom_token.nvgt @@ -0,0 +1,19 @@ +/** + Generates a string of random characters, or token base on the characters you set. + string generate_custom_token(int token_length, characters); + ## Arguments: + * int token_length: the length of the token to generate. + * string characters: a list of characters to generate. + ## returns: + String: a random token. + ## Remarks: + If characters list is empty or token length is set to 0 or less, an empty string is returned. +*/ + +// Example: +#include "token_gen.nvgt" + +void main() { + alert("Info", "Your A to C token is: " + generate_custom_token(10, "abc")); + alert("Info", "A to C with capitals included token is: " + generate_custom_token(10, "abcABC")); +} diff --git a/release/include/token_gen.nvgt b/release/include/token_gen.nvgt index f6ef8b92..6fa93f6d 100644 --- a/release/include/token_gen.nvgt +++ b/release/include/token_gen.nvgt @@ -28,9 +28,12 @@ string generate_token(int token_length, int mode = token_gen_flag_all) { else if (mode == token_gen_flag_symbols) token_sims = symbols; else if (mode == token_gen_flag_numbers_symbols) token_sims = numbers + symbols; else if (mode == token_gen_flag_characters_symbols) token_sims = chars + symbols; - + return generate_custom_token(token_length, token_sims); +} +string generate_custom_token(int token_length, string characters) { + if (characters.empty() || token_length <= 0) return ""; string final_token; for (uint i = 0; i < token_length; i++) - final_token += token_sims[random(0, token_sims.length() - 1)]; - return final_token; -} + final_token += characters[random(0, characters.length() - 1)]; + return final_token; +} \ No newline at end of file