moths

command module
v5.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 5 Imported by: 0

README ยถ

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 ๐Ÿคท

You don't need to use environment variables, this is just my choice.

echo 'moths' | sha256sum | base64 -w 0 | { echo -n "MOTHS_SECRET=$(cat -)" } > .env
  1. Run the program ๐Ÿƒ
go run .

As I said, easy-peasy! ๐Ÿ’–

options ๐Ÿ‘“

To setup a new code-generator, you must call token.NewGenerator as

gen, err := token.NewGenerator()

But I do recommend to add some customization, as it will fail immediately if not.

Like so

gen, err := token.NewGenerator(
  token.OptionWithSecret(secret), // Any string as the secret
  token.OptionWithPeriod(time.Second), // Each code is only valid for a second
  token.OptionWithAmount(6), // Each must is always `6` emojies
  token.OptionWithEmojies(emojies.CATS), // A pure slice of cats
  token.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 code-generator, you can use it as

code, err := gen.Next()

Now that you have a code, you can use its functions

validating ๐Ÿง‘โ€๐Ÿ”ฌ

To validate, you'll need both the code (or the token) and the generator

str := code.String() // Ideally you'd get this from the user
ok := gen.Validate(str)
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 purebred 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 token.OptionWithEmojies(CATS_HOTDOG) when calling the token.NewGenerator().

example ๐Ÿคท

Check out main.go for an example

show-case ๐Ÿ•บ

Three iterations of moths

history โœ

future ๐Ÿ”ฎ

  • Add Skew Intervals ๐Ÿ•ฐ๏ธ
  • Add better documentation ๐Ÿซข
  • Get into fixing geatures ๐Ÿคฆ
  • Rename moth to something better (OTP / Token) - 6105848
  • Rename the Moths-struct to Generator - 4c973ef
    • This means renaming the otp-package as well? - fcdf295
  • Get pkg.go.dev up-to-date - Works with v5

shoutout ๐Ÿ“ข๐Ÿ’จ

I couldn't have done it without these lovely OSS ๐Ÿฆพ

In no specific order ๐Ÿคท

Documentation ยถ

The Go Gopher

There is no documentation for this package.

Directories ยถ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL