Token Generation (token_gen.nvgt)
Token generation include
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.
Enums
token_gen_flag
This enum holds various constants that can be passed to the mode parameter in order to change how tokens are generated in the generate_token
function.
- token_gen_flag_all: Uses all characters, numbers and symbols, see below.
- token_gen_flag_characters: Uses only characters, a-zA-Z
- token_gen_flag_numbers: Uses only numbers, 0-9
- token_gen_flag_symbols: Uses only symbols, `~!@#$%^&*()_+=-[]{}/.,;:|?><
- token_gen_flag_numbers_symbols: Uses numbers and symbols.
- token_gen_flag_characters_symbols: Uses characters and symbols.
Functions
generate_token
Generates a random string of characters (a token).
string generate_token(int token_length, int mode = token_gen_flag_all)
Arguments:
int token_length: the length of the token to generate.
int mode = token_gen_flag_all: allows you to specify which characters you would like in the generated token (see remarks).
returns:
String: a random token depending on the mode.
Remarks:
This function uses the generate_custom_token
function to generate. The characters used to generate the token will depend on the mode you specified. See token_gen_flags
enum constants.
Example:
#include "token_gen.nvgt"
void main() {
alert("Info", "Your token is: " + generate_token(10));
alert("Info", "Numbers only token is: " + generate_token(10, token_gen_flag_numbers));
alert("Info", "Characters only token is: " + generate_token(10, token_gen_flag_characters));
}
generate_custom_token
Generates a random string of characters (a token) while allowing you to directly specify the characters you wish to use in the generation.
string generate_custom_token(int token_length, string 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 the characters
string 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"));
}