1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-16 05:34:49 +00:00
opus/sys/apis/security.lua

57 lines
1.1 KiB
Lua
Raw Normal View History

local Config = require('config')
local Security = { }
function Security.verifyPassword(password)
local current = Security.getPassword()
return current and password == current
end
2017-11-15 05:08:42 +00:00
function Security.hasPassword()
return not not Security.getPassword()
2017-11-15 05:08:42 +00:00
end
function Security.getSecretKey()
local config = Config.load('os')
2018-01-24 22:39:38 +00:00
if not config.secretKey then
config.secretKey = math.random(100000, 999999)
Config.update('os', config)
end
return config.secretKey
end
function Security.getPublicKey()
2018-01-24 22:39:38 +00:00
local exchange = {
base = 11,
primeMod = 625210769
}
2018-01-24 22:39:38 +00:00
local function modexp(base, exponent, modulo)
local remainder = base
2018-01-24 22:39:38 +00:00
for _ = 1, exponent-1 do
remainder = remainder * remainder
if remainder >= modulo then
remainder = remainder % modulo
end
end
2018-01-24 22:39:38 +00:00
return remainder
end
2018-01-24 22:39:38 +00:00
local secretKey = Security.getSecretKey()
return modexp(exchange.base, secretKey, exchange.primeMod)
end
function Security.updatePassword(password)
local config = Config.load('os')
2018-01-24 22:39:38 +00:00
config.password = password
Config.update('os', config)
end
function Security.getPassword()
return Config.load('os').password
end
return Security