Server Connect Custom Module (node/php) Generate 2FA style code

Generate 2FA codes and more with this node/ PHP server connect extension

Generate 2FA allows for the creating of numeric and alphanumeric codes (inc. option special characters), optional repeats of characters and user definable code length.

https://www.npmjs.com/package/@hyperbytes/wappler-2fa-code-generator

Firstly download and install the extension from the NPM repository as per these instructions

Restart Wappler fully and a new icon will be available under "Core Actions"

The interface for this component consists of 3 parameters

Name
Firstly name your component, this is the name of the response used in the JSON response from the module

I call it "code2fa"

Salt
The salt property defines the characters which will be used to construct the code

For numeric, for example use "0123456789"

Salts may also be alphanumeric such as "ADCDEFG1233456", include special characters such as "ABC123$£&" and can contain mixed case such as "ABCDabcd"

Number of Repeats
This allows the re-use of characters up to the defined limit within the code.
For example a salt of "1234" with repeats set to 2 may return duplicate charaters such as "4124" or even "4411"

Length of Code
This defines the length of the returned code.

A sample output using the above settings would be:

{"code2fa":"70709365"}

NOTE: if the code length is set to a length which exceeds the maximum possible characters defined from the salt and repeats then the code will be truncated to the max size possible.

For example a salt of "AB" with 2 repeats max can only produce 4 characters so specifying code length of 6 would simply return a 4 digit code

7 Likes

Thanks Brian!!
:beer:

1 Like

Very useful, great job :beers:

1 Like

Great stuff Brian. This will be very handy indeed.

1 Like

Just in case anyone has issues, i found a problem with the extension which is fixed.

The extension returns {{facode: :xxxx}} but the schema specifies expecting {{facode{code:xxxx}

I have removed the schema so the payload is as first example, no schema.

Now available for php also

2 Likes

Yay! Expect some questions from me soon! I will look to add this to at least one project asap.

Thanks Brian, a star as always.

First question...

Is the NPM covering both Node and PHP? So do I use that for PHP as per your original post?

Yes, Wappler uses npm for both php and node installs.
Just install as normal via the project screen.
No dependencies used so there shouldn't be any issues.
There is a "switch" in the HJSON file to tell npm which platforms are supported by the extension.
A side effect is that you will see some redundant node stuff above the web root (which is not uploaded to server obviously).
Just ignore it was George's response when i raised the issue.
Any problems, just shout for a quick fix (sound like a drug dealer there :sweat_smile:)

HOLD THAT!!!! just found an issue related to the "fs-extra" dependency, wait for update!

All fixed in v1.1.6

Installer was trying to run some old redundant node code on a php server

1 Like

Superb. Thanks again. I will let you know how I get on.