add otp.generate_secret()

This commit is contained in:
BuckarooBanzay 2023-01-28 19:47:01 +01:00
parent 02f90efcaa
commit 10e82093b6
2 changed files with 15 additions and 0 deletions

View file

@ -163,4 +163,13 @@ function otp.create_qr_png(data)
assert(#png_data == width*height) assert(#png_data == width*height)
return minetest.encode_png(width, height, png_data, 2) return minetest.encode_png(width, height, png_data, 2)
end
function otp.generate_secret()
local buf = minetest.sha1("" .. math.random(10000), true)
local s = ""
for i=1,20 do
s = s .. string.char(string.byte(buf, i))
end
return s
end end

View file

@ -57,4 +57,10 @@ mtt.register("otp.create_qr_png", function(callback)
f:write(png) f:write(png)
f:close() f:close()
callback() callback()
end)
mtt.register("otp.generate_secret", function(callback)
local s = otp.generate_secret()
assert(#s == 20)
callback()
end) end)