Skip to content

Instantly share code, notes, and snippets.

@tompave
Created February 3, 2016 15:13
Show Gist options
  • Save tompave/8a5e99d2b7e5b0c66ac6 to your computer and use it in GitHub Desktop.
Save tompave/8a5e99d2b7e5b0c66ac6 to your computer and use it in GitHub Desktop.
require 'digest/md5'
require 'base32'
require 'rqrcode'
require 'rotp'
def print_as_qr(string)
qrcode = RQRCode::QRCode.new(string)
filename = File.expand_path "~/Desktop/qr_#{rand(10_000)}.png"
qrcode.as_png.save(filename, :fast_rgb)
end
def create_qr(totp, email)
uri = totp.provisioning_uri(email)
print_as_qr(uri)
end
email = "[email protected]"
# secret = ROTP::Base32.random_base32
secret = Base32.encode(Digest::MD5.hexdigest(email + "salt")).slice(0,16)
totp = ROTP::TOTP.new(secret, issuer: "AppName")
create_qr(totp, email)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment