A One-Time-Password hash generator in RouterOS is used to have randomness to be used in the generator.
Calling the function is quite flexiable and the ordering of the parameters is not relevant except for the length of the wished string.
Code: Select all
:put [$genpassword 12 letters numbers];
Usage: $genpassword length default/letters/numbers/special/pin/dummyhash
On generating the password, the base-string (default/letters/numbers/special/pin/dummyhash) is mixed to a random sequence and so each password has it's own random base sequence.
The function is made global and all the variables used here are local and so on exit of the function erased by RouterOS. I also put two short global functions named genpin and dummyhash that make it easier of generate a pin or and dummyhash and the default length is four for genpin and 4 for dummyhash. For dummy hash the supplied length is always converted to an even number.
If you see room for improvements then let me know in this thread. Storing the generated passwords/Pin in hashes with salting is not something that is easy doable with the tools available in RouterOS, saldly.
I put the code itself in the second posting in this thread.
Update: added the option to provide your own base string/range to base a password or mixed output on.
Example:
Code: Select all
:set $pass [$genpassword 20 ownbase="10"]; :put $pass