2019-06-28 17:50:02 +00:00
|
|
|
local Config = require('opus.config')
|
2017-09-05 06:09:31 +00:00
|
|
|
|
|
|
|
local Security = { }
|
|
|
|
|
|
|
|
function Security.verifyPassword(password)
|
2019-04-08 13:30:47 +00:00
|
|
|
local current = Security.getPassword()
|
|
|
|
return current and password == current
|
2017-09-05 06:09:31 +00:00
|
|
|
end
|
|
|
|
|
2017-11-15 05:08:42 +00:00
|
|
|
function Security.hasPassword()
|
2019-04-08 13:30:47 +00:00
|
|
|
return not not Security.getPassword()
|
2017-11-15 05:08:42 +00:00
|
|
|
end
|
|
|
|
|
2019-06-29 20:35:33 +00:00
|
|
|
function Security.getIdentifier()
|
|
|
|
local config = Config.load('os')
|
2019-06-30 03:43:21 +00:00
|
|
|
|
|
|
|
if not config.identifier then
|
|
|
|
local key = { }
|
|
|
|
for _ = 1, 32 do
|
|
|
|
table.insert(key, ("%02x"):format(math.random(0, 0xFF)))
|
|
|
|
end
|
|
|
|
config.identifier = table.concat(key)
|
|
|
|
|
|
|
|
Config.update('os', config)
|
2019-06-29 20:35:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return config.identifier
|
2017-09-05 06:09:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Security.updatePassword(password)
|
2019-04-08 13:30:47 +00:00
|
|
|
local config = Config.load('os')
|
2018-01-24 22:39:38 +00:00
|
|
|
config.password = password
|
|
|
|
Config.update('os', config)
|
2017-09-05 06:09:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Security.getPassword()
|
2019-04-08 13:30:47 +00:00
|
|
|
return Config.load('os').password
|
2017-09-05 06:09:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return Security
|