motp

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 5 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MOTP

type MOTP struct {
	// contains filtered or unexported fields
}

MOTP represents a Mobile-OTP (mOTP) generator.

func New

func New(secret, pin string, options ...MOTPOption) (*MOTP, error)

New creates a new MOTP instance with the specified parameters and options. Default values: - period: 10 (default period in seconds) - digits: 6 (default number of digits in OTP)

func (*MOTP) Generate

func (m *MOTP) Generate(unixSeconds int64) (string, error)

NewMOTP creates a new MOTP instance with the specified parameters and options. Default values: - period: 10 (default period in seconds) - digits: 6 (default number of digits in OTP)

func (*MOTP) GenerateCurrent

func (m *MOTP) GenerateCurrent() (string, error)

GenerateCurrent generates a Mobile-OTP (mOTP) code based on the current Unix timestamp.

type MOTPOption

type MOTPOption func(*MOTP) error

MOTPOption is a functional option for configuring MOTP instances.

func WithDigits

func WithDigits(digits uint) MOTPOption

WithDigits configures the number of digits in the MOTP code.

func WithPeriod

func WithPeriod(period uint) MOTPOption

WithPeriod configures the period (in seconds) for the MOTP generator.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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