Giter Club home page Giter Club logo

motp's Introduction

MOTP

motp is a Go package that provides a Mobile-OTP (mOTP) generator. This package allows you to generate time-based one-time passwords (OTP) using a secret key and a PIN.

itpey motp Go Reference itpey motp license

Features

  • Configurable period for OTP validity
  • Configurable number of digits in the OTP
  • Generates OTP based on the current Unix timestamp

Installation

To install the package, use the following command:

go get github.com/itpey/motp

Usage

Creating a New MOTP Instance

You can create a new MOTP instance by specifying a secret key and a PIN. Optionally, you can configure the period and the number of digits for the OTP.

package main

import (
    "fmt"
    "log"
    "github.com/itpey/motp"
)

func main() {
    // Create a new MOTP instance with default settings
    motpInstance, err := motp.New("your_secret_key", "your_pin")
    if err != nil {
        log.Fatalf("Error creating MOTP instance: %v", err)
    }

    // Generate an OTP based on the current Unix timestamp
    otp, err := motpInstance.GenerateCurrent()
    if err != nil {
        log.Fatalf("Error generating OTP: %v", err)
    }

    fmt.Printf("Generated OTP: %s\n", otp)
}

Configuring the Period and Number of Digits

You can customize the period and the number of digits in the OTP by using functional options:

package main

import (
    "fmt"
    "log"
    "github.com/itpey/motp"
)

func main() {
    // Create a new MOTP instance with custom period and digits
    motpInstance, err := motp.New("your_secret_key", "your_pin", motp.WithPeriod(30), motp.WithDigits(8))
    if err != nil {
        log.Fatalf("Error creating MOTP instance: %v", err)
    }

    // Generate an OTP based on the current Unix timestamp
    otp, err := motpInstance.GenerateCurrent()
    if err != nil {
        log.Fatalf("Error generating OTP: %v", err)
    }

    fmt.Printf("Generated OTP: %s\n", otp)
}

CLI Tool

The motp-cli is a command-line tool for generating one-time passwords (OTPs) using the Mobile-OTP (mOTP)algorithm. It allows you to specify a secret key and a PIN to generate a unique OTP based on the current time period.

Installation

Make sure you have Go installed and configured on your system. Use go install to install motp-cli:

go install github.com/itpey/motp/cmd/motp@latest

Ensure that your GOBIN directory is in your PATH for the installed binary to be accessible globally.

Usage

$ motp --secret your_secret_key --pin your_pin --duration duration --length length

Flags

  • --secret, -s: mOTP secret value (often hex or alphanumeric digits) [required]
  • --pin, -p: mOTP PIN value (usually 4 digits) [required]
  • --duration, -d: Duration of mOTP codes in seconds (default 10s) [optional]
  • --length, -l: Length of mOTP output (default 6 characters) [optional]

Example

$ motp --secret mysecret --pin 1234 --duration 30 --length 8

Feedback and Contributions

If you encounter any issues or have suggestions for improvement, please open an issue on GitHub.

We welcome contributions! Fork the repository, make your changes, and submit a pull request.

License

motp is open-source software released under the MIT License. You can find a copy of the license in the LICENSE file.

Author

motp was created by itpey

motp's People

Contributors

itpey avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.