Skip to content

Instantly share code, notes, and snippets.

@niallsmart
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niallsmart/07efcf624249ee84e62e to your computer and use it in GitHub Desktop.
Save niallsmart/07efcf624249ee84e62e to your computer and use it in GitHub Desktop.
TOTP tester using rotp gem
require 'rotp'
require 'qrencoder'
random = "m5qckrq57y2s6232"
totp = ROTP::TOTP.new(random)
qr_string = totp.provisioning_uri("niall.smart@gethightower.com")
qr_code = QREncoder.encode(qr_string)
qr_code.png(pixels_per_module: 4, margin: 1).save("qr_code.png")
puts "OK. Now open qr_code.png and scan it into Google Authenticator."
puts ""
loop do
printf("What is your most excelent OTP? ")
otp = gets.chop
puts totp.verify_with_drift(otp, 120)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment