I'm learning Elixir and gave myself a challenge to write a TOTP client with it.
At the moment it's more a proof of concept than a client, there is no interface. It's a work in process.
Clone the directory :
git clone [email protected]:jameslafa/totpex.git
cd totpex
In debug mode:
iex -S mix
iex(1)> Totpex.generate_totp("mysecretkey_base32encoded")
"798396"
As a standalone application
# build binary (one time operation)
mix escript.build
# Execute application
./totpex
Please enter your secret key: 634hszwpdilkzqe2
Your One-Time Password is 382765
- Elixir installed
- A computer running at the correct time. Most of the system are automatically so it shouldn't be a problem.
- A Base32 encoded secret key given by the service you enabled 2 factor authentication on.
- Go to your security settings
- Click on Set up two-factor authentication
- Choose Set up using an app. If you don't have Google Authenticator installed on your phone, get it from your App Store
- Scan the square code from your app, then it's safe and easy to use from your phone
- Click on enter this text code to get the Base32 encoded value. Save it somewhere safe
- Enter the value generated by your phone
- Click on Enable 2 factor authentication
You can now use your secret key obtained at step 5 and compare the generated value with the one given by your phone.
I want to thank my friend Alexandre who helped me to understand the Java code of the official documentation.
I want also to thank the authors of the following articles or projects, it was a great help:
- How Google Authenticator Works
- robbiev/two-factor-auth written in Go
- Google Authenticator One-time Password Algorithm in Javascript
- trustatom-oss/exotp written in Elixir. The project didn't work for me but it helped me to understand binary manipulation with Elixir.
Contact me on twitter @jameslafa