Adding language hint for markdown examples.
This commit is contained in:
parent
395d932f93
commit
6ad513fa31
49
README.md
49
README.md
@ -7,14 +7,14 @@ Go library for generating and using One Time Passwords. Supports both HOTP ([RFC
|
||||
## Examples
|
||||
|
||||
### OTP Server
|
||||
|
||||
import (
|
||||
```go
|
||||
import (
|
||||
"dev.justinjudd.org/justin/otp"
|
||||
)
|
||||
)
|
||||
|
||||
var Issuer = "example.com"
|
||||
var Issuer = "example.com"
|
||||
|
||||
func CreateKeyForUser(user string) {
|
||||
func CreateKeyForUser(user string) {
|
||||
|
||||
opts := otp.NewHOTPKeyOptions()
|
||||
opts.Issuer = Issuer
|
||||
@ -26,19 +26,19 @@ Go library for generating and using One Time Passwords. Supports both HOTP ([RFC
|
||||
|
||||
// Provide the URL to the customer so they can include it in their 2FA client.
|
||||
// Can email URL, or present QR code encoding of the URL
|
||||
}
|
||||
}
|
||||
|
||||
// Store this string variable in your database
|
||||
func Store(user, url string) {
|
||||
// Store this string variable in your database
|
||||
func Store(user, url string) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the url string variable from your database
|
||||
func GetURL(user string) string {
|
||||
// Retrieve the url string variable from your database
|
||||
func GetURL(user string) string {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func CheckUsersCode(user string, code string) (bool, error) {
|
||||
func CheckUsersCode(user string, code string) (bool, error) {
|
||||
keyURL := GetURL(user)
|
||||
|
||||
key, err := otp.FromURL(keyURL)
|
||||
@ -59,25 +59,25 @@ Go library for generating and using One Time Passwords. Supports both HOTP ([RFC
|
||||
|
||||
return success, nil
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
### OTP Client
|
||||
|
||||
import (
|
||||
```go
|
||||
import (
|
||||
"dev.justinjudd.org/justin/otp"
|
||||
)
|
||||
)
|
||||
|
||||
// Just an example for storing OTP keys on the client
|
||||
var keys map[Key]string
|
||||
// Just an example for storing OTP keys on the client
|
||||
var keys map[Key]string
|
||||
|
||||
|
||||
// Key is used as keys for the otp key storing map
|
||||
type Key struct {
|
||||
// Key is used as keys for the otp key storing map
|
||||
type Key struct {
|
||||
Issuer, Label string
|
||||
}
|
||||
}
|
||||
|
||||
func GetCode(issuer, username string) (string, error) {
|
||||
func GetCode(issuer, username string) (string, error) {
|
||||
|
||||
mapKey := Key{issuer, username}
|
||||
|
||||
@ -105,4 +105,5 @@ Go library for generating and using One Time Passwords. Supports both HOTP ([RFC
|
||||
keys[mapKey]= keyURL
|
||||
|
||||
return code, nil
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user