You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using this library to generate a QR code that I connect to Google Authenticator. However, the OTP generated by Google Authenticator doesn't get validated by the library.
version of package
github.com/pquerna/otp v1.4.0
go version
go version go1.22.4 linux/amd64
code:
package main
import (
"fmt""image/png""log""os""github.com/pquerna/otp""github.com/pquerna/otp/totp"
)
funcmain() {
key, err:=totp.Generate(totp.GenerateOpts{
Issuer: "localhost:8000",
AccountName: "[email protected]",
SecretSize: 32,
})
iferr!=nil {
log.Fatalf("Failed to generate OTP: %v", err)
}
qrImage, err:=key.Image(256, 256)
iferr!=nil {
log.Fatalf("Failed to generate QR code image: %v", err)
}
file, err:=os.Create("otp_qrcode.png")
iferr!=nil {
log.Fatalf("Failed to create file for QR code: %v", err)
}
deferfile.Close()
iferr:=png.Encode(file, qrImage); err!=nil {
log.Fatalf("Failed to save QR code image: %v", err)
}
fmt.Println("QR code generated and saved as otp_qrcode.png")
fmt.Print("Enter the OTP code from your authenticator app: ")
varotpCodestringfmt.Scanln(&otpCode)
valid:=totp.Validate(otpCode, key.Secret())
ifvalid {
fmt.Println("OTP verified successfully!")
} else {
fmt.Println("Invalid OTP code.")
}
}
to reproduce:
Run the code provided above.
Scan the generated QR code using Google Authenticator.
Enter the OTP code displayed in Google Authenticator into the terminal.
The text was updated successfully, but these errors were encountered:
I am using this library to generate a QR code that I connect to Google Authenticator. However, the OTP generated by Google Authenticator doesn't get validated by the library.
version of package
go version
code:
to reproduce:
Run the code provided above.
Scan the generated QR code using Google Authenticator.
Enter the OTP code displayed in Google Authenticator into the terminal.
The text was updated successfully, but these errors were encountered: