8000 GitHub - Mobilpadde/moths at v2.2.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

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

moths 🪰

emojicon authentications

Go Reference

what (is this 💩)

Emojies as TOTP, because.

why

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:

  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. Make a secret of 32 characters 🔐
echo -n "MOTHS_SECRET=" > .env
echo 'moths' | sha256sum | base64 | head -c 32 >> .env
  1. Run the program 🏃
go run .

As I said, easy-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.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
  • 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
  • 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

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

  • 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
  • SpacedString() string
    • Returns the moth as a string with spaces inbetween the emojies
  • Slice() []string
    • Returns the moth as a slice of strings

validating

To validate, you'll need both the OTP and the generator

ok := gen.Validate(otp.String())

example

Check out main.go for an example

sample 🤔

First generation of a moth Second generation of a moth

history ✍

shoutout 📢💨

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

In no specific order 🤷

About

moths: emojicon authentications

Topics

Resources

License

Stars

Watchers

Forks

Languages

0