This Go package is to generate One-Time Password for Email based Accoounts
In your development environment,- Install OTP-Go:
go get github.com/seyiadel/otp-go/otp
- Import and run
go mod tidy
import ("gorm.io/gorm)
and gorm driver import "gorm.io/driver/sqlite"
for your preferred database. Check Gorm.io driver.
For Example using sqlite database and driver,
conn, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
if err != nil{
panic("failed to connect to database")
}
Now you can call the package methods to validate and generate OTP.
otp.Generate(conn,"[email protected]", 4)
as conn is the database, [email protected] is the user email, 4 is the desired otp length
otp.ValidateOTP(conn, "[email protected]", 7645)
as conn is the database, [email protected] is the user email, 7645 is the token generated