• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

example/H11-Nov-2020-8268

hotp/H11-Nov-2020-395274

interop/H11-Nov-2020-6538

totp/H11-Nov-2020-378260

.travis.ymlH A D11-Nov-202082 118

LICENSEH A D11-Nov-202011.1 KiB203169

NOTICEH A D11-Nov-2020121 64

README.mdH A D11-Nov-20203.5 KiB6137

doc.goH A D11-Nov-20202.2 KiB711

go.modH A D11-Nov-2020155 96

go.sumH A D11-Nov-20201,018 1211

otp.goH A D11-Nov-20204.7 KiB224135

otp_test.goH A D11-Nov-20202 KiB5632

README.md

1# otp: One Time Password utilities Go / Golang
2
3[![PkgGoDev](https://pkg.go.dev/badge/github.com/pquerna/otp)](https://pkg.go.dev/github.com/pquerna/otp) [![Build Status](https://travis-ci.org/pquerna/otp.svg?branch=master)](https://travis-ci.org/pquerna/otp)
4
5# Why One Time Passwords?
6
7One Time Passwords (OTPs) are an mechanism to  improve security over passwords alone. When a Time-based OTP (TOTP) is stored on a user's phone, and combined with something the user knows (Password), you have an easy on-ramp to [Multi-factor authentication](http://en.wikipedia.org/wiki/Multi-factor_authentication) without adding a dependency on a SMS provider.  This Password and TOTP combination is used by many popular websites including Google, Github, Facebook, Salesforce and many others.
8
9The `otp` library enables you to easily add TOTPs to your own application, increasing your user's security against mass-password breaches and malware.
10
11Because TOTP is standardized and widely deployed, there are many [mobile clients and software implementations](http://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm#Client_implementations).
12
13## `otp` Supports:
14
15* Generating QR Code images for easy user enrollment.
16* Time-based One-time Password Algorithm (TOTP) (RFC 6238): Time based OTP, the most commonly used method.
17* HMAC-based One-time Password Algorithm (HOTP) (RFC 4226): Counter based OTP, which TOTP is based upon.
18* Generation and Validation of codes for either algorithm.
19
20## Implementing TOTP in your application:
21
22### User Enrollment
23
24For an example of a working enrollment work flow, [Github has documented theirs](https://help.github.com/articles/configuring-two-factor-authentication-via-a-totp-mobile-app/
25),  but the basics are:
26
271. Generate new TOTP Key for a User. `key,_ := totp.Generate(...)`.
281. Display the Key's Secret and QR-Code for the User. `key.Secret()` and `key.Image(...)`.
291. Test that the user can successfully use their TOTP. `totp.Validate(...)`.
301. Store TOTP Secret for the User in your backend. `key.Secret()`
311. Provide the user with "recovery codes". (See Recovery Codes bellow)
32
33### Code Generation
34
35* In either TOTP or HOTP cases, use the `GenerateCode` function and a counter or
36  `time.Time` struct to generate a valid code compatible with most implementations.
37* For uncommon or custom settings, or to catch unlikely errors, use `GenerateCodeCustom`
38  in either module.
39
40### Validation
41
421. Prompt and validate User's password as normal.
431. If the user has TOTP enabled, prompt for TOTP passcode.
441. Retrieve the User's TOTP Secret from your backend.
451. Validate the user's passcode. `totp.Validate(...)`
46
47
48### Recovery Codes
49
50When a user loses access to their TOTP device, they would no longer have access to their account.  Because TOTPs are often configured on mobile devices that can be lost, stolen or damaged, this is a common problem. For this reason many providers give their users "backup codes" or "recovery codes".  These are a set of one time use codes that can be used instead of the TOTP.  These can simply be randomly generated strings that you store in your backend.  [Github's documentation provides an overview of the user experience](
51https://help.github.com/articles/downloading-your-two-factor-authentication-recovery-codes/).
52
53
54## Improvements, bugs, adding feature, etc:
55
56Please [open issues in Github](https://github.com/pquerna/otp/issues) for ideas, bugs, and general thoughts.  Pull requests are of course preferred :)
57
58## License
59
60`otp` is licensed under the [Apache License, Version 2.0](./LICENSE)
61