mirror of
https://git.phreedom.club/localhost_frssoft/fediauth.git
synced 2024-11-22 07:51:29 +00:00
better qr code
This commit is contained in:
parent
a28f9c1cb2
commit
b1bbe1f8dc
|
@ -142,12 +142,18 @@ function otp.generate_totp(secret_b32, unix_time)
|
|||
end
|
||||
|
||||
function otp.create_qr_png(data)
|
||||
local height = #data
|
||||
local height = #data + 2
|
||||
local width = height
|
||||
|
||||
local png_data = {}
|
||||
-- top padding
|
||||
for _=1,width do
|
||||
table.insert(png_data, 0xFFFFFFFF)
|
||||
end
|
||||
|
||||
for _, row in ipairs(data) do
|
||||
assert(#row == #data)
|
||||
-- left padding
|
||||
table.insert(png_data, 0xFFFFFFFF)
|
||||
for _, v in ipairs(row) do
|
||||
if v > 0 then
|
||||
table.insert(png_data, 0xFF000000)
|
||||
|
@ -155,9 +161,16 @@ function otp.create_qr_png(data)
|
|||
table.insert(png_data, 0xFFFFFFFF)
|
||||
end
|
||||
end
|
||||
-- right padding
|
||||
table.insert(png_data, 0xFFFFFFFF)
|
||||
end
|
||||
assert(#png_data == width*height)
|
||||
|
||||
-- bottom padding
|
||||
for _=1,width do
|
||||
table.insert(png_data, 0xFFFFFFFF)
|
||||
end
|
||||
|
||||
assert(#png_data == width*height)
|
||||
return minetest.encode_png(width, height, png_data, 2)
|
||||
end
|
||||
|
||||
|
|
|
@ -26,9 +26,12 @@ minetest.register_chatcommand("otp_enable", {
|
|||
local secret_b32 = otp.get_player_secret_b32(name)
|
||||
|
||||
-- url for the qr code
|
||||
local url = "otpauth://totp/" .. issuer .. ":" .. name .. "?algorithm=SHA1&" ..
|
||||
"digits=6&issuer=" .. issuer .. "&period=30&" ..
|
||||
"secret=" .. secret_b32
|
||||
local url = "otpauth://totp/" .. issuer .. ":" .. name .. "?algorithm=SHA1" ..
|
||||
"&digits=6" ..
|
||||
"&issuer=" .. issuer ..
|
||||
"&period=30" ..
|
||||
"&secret=" .. secret_b32 ..
|
||||
"&image=https://raw.githubusercontent.com/minetest/minetest/master/misc/minetest-xorg-icon-128.png"
|
||||
|
||||
local ok, code = otp.qrcode(url)
|
||||
if not ok then
|
||||
|
|
Loading…
Reference in a new issue