8000 GitHub - Mobilpadde/moths at v4.0.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Mobilpadde/moths

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

moths 🪰

emojicon authentications

Go Reference

what (is this 💩)

Emojies as TOTP, because.

why 🥲

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:

  1. 🦋
  2. 🐰
  3. 🐶
  4. 🐕
  5. 🐷
  6. 🐥
  7. 🐱
  8. 🐣
  9. 🐻
  10. 🐈

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 ✨

how 🧑‍💼

Running this is quite easy 💨

  1. Download the dependencies ⏬

Note

You can skip this step and let the run-command handle it - but you knew that 🧠

go mod download
  1. Add a secret 🔐

Warning

This is just an one-liner to write the base64-encoded sha256 of moths 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.

  1. Run the program 🏃
go run .

As I said, easy 8000 -peasy! 💖

options 👓

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

Warning

Options marked with an asterix (*) are required!

generating 🖇

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

validating 🧑‍🔬

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)

emojies 😻

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().

example 🤷

Check out main.go for an example

show-case 🕺

Three iterations of moths

history ✍

future 🔮

  • Rename moth to something better (OTP / Token)
  • Add better documentation 🫢
  • Rename the gen-variable to otp
    • This means renaming the otp-package as well?
  • Get pkg.go.dev up-to-date

shoutout 📢💨

I couldn't have done it without these lovely OSS 🦾

In no specific order 🤷

0