Skip to content

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.

Functions

generate_token

Generates a random string of characters (a token).

string generate_token(int token_length, int mode = token_gen_flag_all)

Arguments:

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:

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"));
}