Created
February 3, 2016 15:13
-
-
Save tompave/8a5e99d2b7e5b0c66ac6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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