2018-12-23 03:11:16 +00:00
|
|
|
local Security = require('security')
|
2019-06-28 10:33:47 +00:00
|
|
|
local SHA = require('crypto.sha2')
|
2018-12-23 03:11:16 +00:00
|
|
|
local UI = require('ui')
|
|
|
|
|
2019-02-26 23:03:09 +00:00
|
|
|
local colors = _G.colors
|
|
|
|
|
2019-01-30 20:11:41 +00:00
|
|
|
local passwordTab = UI.Tab {
|
2018-12-23 03:11:16 +00:00
|
|
|
tabTitle = 'Password',
|
|
|
|
description = 'Wireless network password',
|
|
|
|
oldPass = UI.TextEntry {
|
2019-02-26 23:03:09 +00:00
|
|
|
x = 3, ex = -3, y = 2,
|
2018-12-23 03:11:16 +00:00
|
|
|
limit = 32,
|
|
|
|
mask = true,
|
|
|
|
shadowText = 'old password',
|
|
|
|
inactive = not Security.getPassword(),
|
|
|
|
},
|
|
|
|
newPass = UI.TextEntry {
|
2019-02-26 23:03:09 +00:00
|
|
|
x = 3, ex = -3, y = 3,
|
2018-12-23 03:11:16 +00:00
|
|
|
limit = 32,
|
|
|
|
mask = true,
|
|
|
|
shadowText = 'new password',
|
|
|
|
accelerators = {
|
|
|
|
enter = 'new_password',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
button = UI.Button {
|
2019-02-26 23:03:09 +00:00
|
|
|
x = 3, y = 5,
|
2018-12-23 03:11:16 +00:00
|
|
|
text = 'Update',
|
|
|
|
event = 'update_password',
|
|
|
|
},
|
|
|
|
info = UI.TextArea {
|
2019-02-26 23:03:09 +00:00
|
|
|
x = 3, ex = -3, y = 7,
|
|
|
|
textColor = colors.yellow,
|
2018-12-23 03:11:16 +00:00
|
|
|
inactive = true,
|
|
|
|
value = 'Add a password to enable other computers to connect to this one.',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function passwordTab:eventHandler(event)
|
|
|
|
if event.type == 'update_password' then
|
|
|
|
if #self.newPass.value == 0 then
|
|
|
|
self:emit({ type = 'error_message', message = 'Invalid password' })
|
|
|
|
|
2019-06-28 10:33:47 +00:00
|
|
|
elseif Security.getPassword() and not Security.verifyPassword(SHA.compute(self.oldPass.value)) then
|
2018-12-23 03:11:16 +00:00
|
|
|
self:emit({ type = 'error_message', message = 'Passwords do not match' })
|
|
|
|
|
|
|
|
else
|
2019-06-28 10:33:47 +00:00
|
|
|
Security.updatePassword(SHA.compute(self.newPass.value))
|
2018-12-23 03:11:16 +00:00
|
|
|
self.oldPass.inactive = false
|
|
|
|
self:emit({ type = 'success_message', message = 'Password updated' })
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return passwordTab
|