سؤال

My understanding (which may obviously be wrong) is that the Authen::OATH module is compatible with the totp codes generated by the Google Authenticator App. But it doesn't work for me, whereas a similar bit of ruby code does. We're a perl shop here and it would help if anyone could point me in the right direction to save me from digging through both libraries line by line.

This ruby works compatibly:

require 'rubygems'

require 'rotp'

secret = "bqagf6ohx4rp3a67"

puts ROTP::TOTP.new(secret).now.to_s

This perl does not:

use Authen::OATH;

my $oath = Authen::OATH->new();

my $totp = $oath->totp(" bqagf6ohx4rp3a67" );

print "$totp\n";
هل كانت مفيدة؟

المحلول

It's not very clear from the documentation, but Authen::OATH expects the unencoded passwords to totp and hotp. If that's not an option, you could try decode_base32 from Convert::Base32

use Convert::Base32;
use Authen::OATH;

my $oath = Authen::OATH->new();

my $totp = $oath->totp( decode_base32( "bqagf6ohx4rp3a67" ) );

print "$totp\n";
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top