https://github.com/RijulGulati/otpgen
Library to generate TOTP/HOTP codes
https://github.com/RijulGulati/otpgen
cli golang golang-library hotp linux otpgen totp
Last synced: 8 months ago
JSON representation
Library to generate TOTP/HOTP codes
- Host: GitHub
- URL: https://github.com/RijulGulati/otpgen
- Owner: RijulGulati
- License: mit
- Created: 2021-06-01T18:02:59.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-17T05:55:45.000Z (almost 2 years ago)
- Last Synced: 2024-04-13T20:10:22.610Z (over 1 year ago)
- Topics: cli, golang, golang-library, hotp, linux, otpgen, totp
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 133
- Watchers: 3
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - otpgen - Library to generate TOTP/HOTP codes. (Authentication and OAuth)
- awesome-go - RijulGulati/otpgen
README
# otpgen
Library to generate TOTP/HOTP codes
## Installation
```sh
go get -u github.com/grijul/otpgen
```
## Usage
Here is a sample demonstration
```go
package main
import (
"fmt"
"github.com/grijul/otpgen"
)
func main() {
// Generate TOTP
totp := otpgen.TOTP{
Secret: "testpass",
Digits: 8, //(optional) (default: 6)
Algorithm: "SHA256", //(optional) (default: SHA1)
Period: 45, //(optional) (default: 30)
UnixTime: 11111111, //(optional) (default: Current Unix Time)
}
if otp, err := totp.Generate(); err == nil {
fmt.Println(otp)
} else {
fmt.Println(err.Error())
}
// Generate HOTP
hotp := otpgen.HOTP{
Secret: "testsecret",
Counter: 100, //(default: 0)
Digits: 8, //(optional) (default: 6)
}
if otp, err := hotp.Generate(); err == nil {
fmt.Println(otp)
} else {
fmt.Println(err.Error())
}
}
```
# Licence
[MIT](https://github.com/grijul/otpgen/blob/main/LICENSE)