emojicon authentications
Because we all could use a little more emotion in our lives 🤗 Go show the world how you really feel!
It's a great companion for any app that uses 2FA - as every app should! Make your app's 2FA users as star-striking as your app! 🤩
So whether your mascot is:
- 🦋
- 🐰
- 🐶
- 🐕
- 🐷
- 🐥
- 🐱
- 🐣
- 🐻
- 🐈
moths has got you covered! 🪰
P.S. These emojies wasn't chosen by accident (random), they really are the 10 utmost frequently used (animal) emojies of 2021
Show that sparkly emojies ✨
Running this is quite easy 💨
- Download the dependencies ⏬
Note
You can skip this step and let the
run
-command handle it - but you knew that 🧠
go mod download
- Make a secret of 32 characters 🔐
echo -n "MOTHS_SECRET=" > .env
echo 'moths' | sha256sum | base64 | head -c 32 >> .env
- Run the program 🏃
go run .
As I said, easy-peasy! 💖
To setup a new moth
-generator, you must call moths.NewMoths
as
gen, err := moths.NewMoths()
But I do recommend to add some customization, as it will fail immediately if not.
Like so
gen, err := moths.NewMoths(
moths.WithSecret(secret),
moths.WithInterval(generationInterval),
moths.WithAmount(amount),
moths.WithEmojies(emojies.CATS),
moths.WithTime(time.Now().AddDate(10, 0, 0)), // 10 years into the future
)
There are a few options to choose from, these are
WithSecret(secret string)
*- The secret to generate from
- Must be 32 characters ⚠
WithInterval(interval time.Duration)
*- On which interval should a new
moth
be generated - A
moth
will only be valid during this time-frame
- On which interval should a new
WithAmount(amount int)
*- The amount of emojies to generate
WithEmojies(emojies emojies.Emojies)
*- Take a look in the
emojies
-package to see your options - You can also add new emojies
- Take a look in the
WithTime(t time.Time)
- This will allow you to add a custom time
- Meaning you can validate towards old
moths
- You can even add a future date ⌛
Options marked with an asterix (*) are required
Now that you have a sparkly new moth
-generator, you can use it as
otp, err := gen.Next()
Now that you have an OTP
, you can use its functions
Validate(moth string) bool
- Will validate a moth directly (the pattern of emojies)
ValidateToken(code string) bool
- Will validate OTP code
- You'll need to expose the code for your user too, for this
Token() string
- Returns the token - for whatever reason that might be needed
String() string
- Returns the
moth
as a string
- Returns the
SpacedString() string
- Returns the
moth
as a string with spaces inbetween the emojies
- Returns the
Slice() []string
- Returns the
moth
as a slice of strings
- Returns the
To validate, you'll need both the OTP
and the generator
ok := gen.Validate(otp.String())
Check out main.go
for an example
I couldn't have done it without these lovely OSS 🦾
- https://github.com/aidarkhanov/nanoid
- https://github.com/enescakir/emoji
- https://github.com/tilaklodha/google-authenticator
- https://github.com/pquerna/otp/
In no specific order 🤷