emojicon authentications
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 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
- Add a secret 🔐
Warning
This is just an one-liner to write the
base64
-encodedsha256
ofmoths
into.env
. Make sure to use something better 🤷
echo 'moths' | sha256sum | base64 -w 0 | { echo -n "MOTHS_SECRET=$(cat -)" } > .env
Note
You don't need to use environment variables, this is just my choice.
- Run the program 🏃
go run .
As I said, easy 8000 -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.OptionWithSecret(secret), // any string as the secret
moths.OptionWithInterval(time.Second), // Each is only valid for a second
moths.OptionWithAmount(6), // Each must is always `6` emojies
moths.OptionWithEmojies(emojies.CATS), // A pure slice of cats
moths.OptionWithTime(time.Now().AddDate(10, 0, 0)), // 10 years into the future
)
There are a few options to choose from, these are
OptionWithSecret(secret string)
*- The secret to generate from
- Must be 32 characters ⚠
OptionWithInterval(interval time.Duration)
*- On which interval should a new
moth
be generated - A
moth
will only be valid during this duration
- On which interval should a new
OptionWithAmount(amount int)
- The amount of emojies to generate in a
moth
- Defaults to
6
-charater tokens
- The amount of emojies to generate in a
OptionWithEmojies(emojies emojies.Emojies)
*OptionWithTime(t time.Time)
- This will allow you to add a custom time
- Meaning you can validate towards old
moths
- You can even add future dates ⌛
- Defaults to now
Warning
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 (pattern of emojies) directly
ValidateToken(token string) bool
- Will validate a OTP token
- You'll need to expose the code for your user too, for this - not recommended
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
- Returns the
Slice() []string
- Returns the
moth
as a slice of strings
- Returns the
To validate, you'll need both the moth
(or the token
) and the generator
token := otp.String() // Ideally you'd get this from the user
ok := gen.Validate(token)
To use your own set of known emojies, you can reference the cat
-emojies.
I've chosen the cats
as it's a great reference, both for creating and re-using.
If we would like to add an easter-egg to a pure bred slice of cats, we could do it like:
// A slice of cat emojies and a single hotdog 🌭
var catsHotdog = []string{
emoji.GrinningCat.String(),
emoji.GrinningCatWithSmilingEyes.String(),
emoji.CatWithTearsOfJoy.String(),
emoji.SmilingCatWithHeartEyes.String(),
emoji.CatWithWrySmile.String(),
emoji.KissingCat.String(),
emoji.WearyCat.String(),
emoji.CryingCat.String(),
emoji.PoutingCat.String(),
emoji.HotDog.String(),
}
var CATS_HOTDOG = ToEmojies(catsHotdog)
It doesn't even have to be from the emoji-package,
simply make a slice of your desired emojies, and use the ToEmojies
-func.
Then provide this as an argument in moths.OptionWithEmojies(CATS_HOTDOG)
when calling the moths.NewMoths()
.
Check out main.go
for an example
-
v4.0.0
💘
- Rename
moth
to something better (OTP
/Token
) - Add better documentation 🫢
- Rename the
gen
-variable tootp
- This means renaming the
otp
-package as well?
- This means renaming the
- Get pkg.go.dev up-to-date
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 🤷