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 | ## Examples | ||||||
| 
 | 
 | ||||||
| ### OTP Server | ### OTP Server | ||||||
| 
 | ```go | ||||||
|     import ( | import ( | ||||||
|   "dev.justinjudd.org/justin/otp" |   "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 := otp.NewHOTPKeyOptions() | ||||||
|   opts.Issuer = Issuer |   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. |   // 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 |   // Can email URL, or present QR code encoding of the URL | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     // Store this string variable in your database | // Store this string variable in your database | ||||||
|     func Store(user, url string) { | func Store(user, url string) { | ||||||
| 
 | 
 | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     // Retrieve the url string variable from your database | // Retrieve the url string variable from your database | ||||||
|     func GetURL(user string) string { | func GetURL(user string) string { | ||||||
|   return "" |   return "" | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     func CheckUsersCode(user string, code string) (bool, error) { | func CheckUsersCode(user string, code string) (bool, error) { | ||||||
|   keyURL := GetURL(user) |   keyURL := GetURL(user) | ||||||
| 
 | 
 | ||||||
|   key, err := otp.FromURL(keyURL) |   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 |   return success, nil | ||||||
|     } |     } | ||||||
| 
 | ``` | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| ### OTP Client | ### OTP Client | ||||||
| 
 | ```go | ||||||
|     import ( | import ( | ||||||
|   "dev.justinjudd.org/justin/otp" |   "dev.justinjudd.org/justin/otp" | ||||||
|     ) | ) | ||||||
| 
 | 
 | ||||||
|     // Just an example for storing OTP keys on the client | // Just an example for storing OTP keys on the client | ||||||
|     var keys map[Key]string | var keys map[Key]string | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     // Key is used as keys for the otp key storing map | // Key is used as keys for the otp key storing map | ||||||
|     type Key struct { | type Key struct { | ||||||
| 	Issuer, Label string | 	Issuer, Label string | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     func GetCode(issuer, username string) (string, error) { | func GetCode(issuer, username string) (string, error) { | ||||||
| 
 | 
 | ||||||
|   mapKey := Key{issuer, username} |   mapKey := Key{issuer, username} | ||||||
| 
 | 
 | ||||||
| @ -105,4 +105,5 @@ Go library for generating and using One Time Passwords. Supports both HOTP ([RFC | |||||||
|   keys[mapKey]= keyURL |   keys[mapKey]= keyURL | ||||||
| 
 | 
 | ||||||
|   return code, nil |   return code, nil | ||||||
|     } | } | ||||||
|  | ``` | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Justin Judd
						Justin Judd