Documentation ¶
Overview ¶
Package captcha contains methods to generate captchas. There are two basic methods: normal captchas and timed captchas. A captcha consists of a captcha and an id. The id can be shown publicly, the captcha should be guessed by humans. A captcha can not be derivated from an id other than through brute force. The verification of a captcha soley depends on the id, so no state is required. This also means that you can use the functions parallel without problems or side effects. There are two caviats, though: * A hidden value is used to make predictions impossible. This means that whenever you restart the program, old captchas are no longer valid. * No session management is implemented. One captcha / id combination is always valid (as long as the hidden value is the same).
Normal only captchas consist of a id / captcha combination. Therefore, you are strongly advised to use some sort of session management. Timed captchas are valid for a specified amount of time. Therefore, a session management might not be needed (but you might use one, too).
Index ¶
- Constants
- func Get(randomSize int) (id, captcha []byte, err error)
- func GetStrings() (id, captcha string, err error)
- func GetStringsTimed(start time.Time) (id, captcha string, err error)
- func GetTimed(start time.Time, randomSize int) (id, captcha []byte, err error)
- func Verify(id, captcha []byte, randomSize int) bool
- func VerifyStrings(id, captcha string) bool
- func VerifyStringsTimed(id, captcha string, now time.Time, validDuration time.Duration) bool
- func VerifyTimed(id, captcha []byte, now time.Time, validDuration time.Duration, randomSize int) bool
Constants ¶
const (
// RandomSizeDefault contains the suggested default size for random data.
RandomSizeDefault = 6
)
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get returns one random id / captcha combination. The number of bytes is determined by randomSize.
Can be used concurrent.
func GetStrings ¶
GetStrings returns a string representation of a new captcha (with default size). Please note: You have no access on the original id. See Get for more information about captchas.
Can be used concurrent.
func GetStringsTimed ¶
GetStringsTimed returns a string representation of a new timed captcha (with default size). Please note: You have no access on the original id. See Get for more information about captchas.
Can be used concurrent.
func GetTimed ¶
GetTimed returns one timed random id / captcha combination. The number of bytes is determined by randomSize. start determines the time from which the captcha is valid.
You do not need to remember the time since it is encoded in the id (and can not be tampered with without invalidating the captcha).
Can be used concurrent.
func Verify ¶
Verify validates whether an id / captia combination is valid. randomSize musst correspond to the captcha size and must be the same as at the generation.
Since Verify does not check if an id is already used, the same id / captcha combination is always valid.
Can be used concurrent.
func VerifyStrings ¶
VerifyStrings verifies a string representation of a new captcha (with default size). See Verify for more information about captchas.
Can be used concurrent.
func VerifyStringsTimed ¶
VerifyStringsTimed verifies a string representation of a new timed captcha (with default size). See Verify for more information about captchas.
Can be used concurrent.
func VerifyTimed ¶
func VerifyTimed(id, captcha []byte, now time.Time, validDuration time.Duration, randomSize int) bool
VerifyTimed validates whether an id / captia combination is valid and in date. randomSize musst correspond to the captcha size and must be the same as at the generation. Duration determines how long a captcha should be seen as valid.
Since VerifyTimed does not check if an id is already used, the same id / captcha combination is always valid (in the given time period).
Can be used concurrent.
Types ¶
This section is empty.