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.
- Configurable period for OTP validity
- Configurable number of digits in the OTP
- Generates OTP based on the current Unix timestamp
To install the package, use the following command:
go get github.com/itpey/motp
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)
}
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)
}
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.
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.
$ 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]
$ motp --secret mysecret
--pin 1234
--duration 30
--length 8
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.
motp is open-source software released under the MIT License. You can find a copy of the license in the LICENSE file.
motp was created by itpey