Documentation ¶
Overview ¶
Package dgoogauth implements the one-time password algorithms supported by Google Authenticator
This package supports the HMAC-Based One-time Password (HOTP) algorithm specified in RFC 4226 and the Time-based One-time Password (TOTP) algorithm specified in RFC 6238.
Index ¶
- Variables
- func AesDecrypt(crypted, key []byte) ([]byte, error)
- func AesEncrypt(origData, key []byte) ([]byte, error)
- func ComputeCode(secret string, value int64) int
- func Decrypt(data []byte) ([]byte, error)
- func Encrypt(data []byte) ([]byte, error)
- func GetCurrentPath() string
- func GetPage(c *gin.Context) int
- func MysqlInit()
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PKCS7UnPadding(origData []byte) []byte
- func RandStr(length int) string
- type Cache
- type Config
- type OTPConfig
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCode = errors.New("invalid code")
ErrInvalidCode indicate the supplied one-time code was not valid
var MysqlClient *sql.DB
Functions ¶
func AesDecrypt ¶
func AesEncrypt ¶
func ComputeCode ¶
ComputeCode computes the response code for a 64-bit challenge 'value' using the secret 'secret'. To avoid breaking compatibility with the previous API, it returns an invalid code (-1) when an error occurs, but does not silently ignore them (it forces a mismatch so the code will be rejected).
func GetCurrentPath ¶
func GetCurrentPath() string
func PKCS7Padding ¶
func PKCS7UnPadding ¶
Types ¶
type Config ¶
type Config struct { Mysql struct { Host string `yaml:"host"` Username string `yaml:"username"` Password string `yaml:"password"` Port int `yaml:"port"` Database string `yaml:"database"` } `yaml:"mysql"` Site struct { PageSize int `yaml:"pageSize"` Address string `yaml:"address"` RememberDays int `yaml:"remember_days"` Domain string `yaml:"domain"` UploadPath string `yaml:"uploadPath"` } `yaml:"site"` Recaptcha struct { Secret string `yaml:"secret"` Score float64 `yaml:"score"` } Session struct { MaxAge int `yaml:"maxAge"` } `yaml:"session"` AppKey string `yaml:"appKey"` }
定义配置文件yaml结构
type OTPConfig ¶
type OTPConfig struct { Secret string // 80-bit base32 encoded string of the user's secret WindowSize int // valid range: technically 0..100 or so, but beyond 3-5 is probably bad security HotpCounter int // the current otp counter. 0 if the user uses time-based codes instead. DisallowReuse []int // timestamps in the current window unavailable for re-use ScratchCodes []int // an array of 8-digit numeric codes that can be used to log in UTC bool // use UTC for the timestamp instead of local time }
OTPConfig is a one-time-password configuration. This object will be modified by calls to Authenticate and should be saved to ensure the codes are in fact only used once.
func (*OTPConfig) Authenticate ¶
Authenticate a one-time-password against the given OTPConfig Returns true/false if the authentication was successful. Returns error if the password is incorrectly formatted (not a zero-padded 6 or non-zero-padded 8 digit number).
func (*OTPConfig) ProvisionURI ¶
ProvisionURI generates a URI that can be turned into a QR code to configure a Google Authenticator mobile app.
func (*OTPConfig) ProvisionURIWithIssuer ¶
ProvisionURIWithIssuer generates a URI that can be turned into a QR code to configure a Google Authenticator mobile app. It respects the recommendations on how to avoid conflicting accounts.
See https://github.com/google/google-authenticator/wiki/Conflicting-Accounts