From 3a041ad6d49835f165068f34bba19b8cb1ecd3cc Mon Sep 17 00:00:00 2001 From: Dominique Boucher Date: Tue, 2 Jun 2015 21:28:15 -0400 Subject: [PATCH 1/2] TOTP period is 30 seconds Google Authenticator uses a period of 30 seconds instead of 60. --- src/qrcode_demo.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qrcode_demo.erl b/src/qrcode_demo.erl index 23cd928..0f73784 100644 --- a/src/qrcode_demo.erl +++ b/src/qrcode_demo.erl @@ -100,7 +100,7 @@ get_pixels0(<<>>, Acc) -> %% totp() -> Key = crypto:sha(<<"password">>), - totp(Key, 60). + totp(Key, 30). totp(Key, Period) -> T = unow() div Period, {hotp(Key, T - 1), hotp(Key, T), hotp(Key, T + 1)}. From a534d26c64a6c3c18527cc8695f978251cadfc26 Mon Sep 17 00:00:00 2001 From: Dominique Boucher Date: Tue, 2 Jun 2015 21:39:29 -0400 Subject: [PATCH 2/2] Put period in token --- src/qrcode_demo.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qrcode_demo.erl b/src/qrcode_demo.erl index 0f73784..c148fda 100644 --- a/src/qrcode_demo.erl +++ b/src/qrcode_demo.erl @@ -44,10 +44,11 @@ -compile(export_all). -define(TTY(Term), io:format(user, "[~p] ~p~n", [?MODULE, Term])). +-define(PERIOD, 30). run() -> Passcode = crypto:sha(<<"password">>), - run(<<"demo@mydomain.com">>, Passcode, 60). + run(<<"demo@mydomain.com">>, Passcode, ?PERIOD). run(Domain, Passcode, Seconds) -> PasscodeBase32 = base32:encode(Passcode), @@ -100,7 +101,7 @@ get_pixels0(<<>>, Acc) -> %% totp() -> Key = crypto:sha(<<"password">>), - totp(Key, 30). + totp(Key, ?PERIOD). totp(Key, Period) -> T = unow() div Period, {hotp(Key, T - 1), hotp(Key, T), hotp(Key, T + 1)}.