Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add password length failsafes for WPA-PSK #1627

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions lua/core/menu/system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ m.key = function(n,z)
_menu.set_page("HOME")
elseif n==3 and z==1 then
if m.pages[m.pos]=="PASSWORD" then
textentry.enter(m.passdone, "", "new password:")
textentry.enter(m.passdone, "", "new password:", m.passcheck)
else
_menu.set_page(m.pages[m.pos])
end
Expand Down Expand Up @@ -45,21 +45,39 @@ end
m.init = norns.none
m.deinit = norns.none

m.passcheck = function(txt)
if txt ~= nil then
if string.len(txt) < 8 then
return ("remaining: "..8 - string.len(txt))
elseif string.len(txt) > 63 then
return ("too long")
end
end
end

m.passdone = function(txt)
if txt ~= nil then
local chpasswd_status = os.execute("echo 'we:"..txt.."' | sudo chpasswd")
local smbpasswd_status = os.execute("printf '"..txt.."\n"..txt.."\n' | sudo smbpasswd -a we")
local hotspotpasswd_status;
local fd = io.open("home/we/norns/.system.hotspot_password", "w+")
if fd then
io.output(fd)
io.write(txt)
io.close(fd)
hotspotpasswd_status = true
if string.len(txt) >= 8 and string.len(txt) < 64 then
local chpasswd_status = os.execute("echo 'we:"..txt.."' | sudo chpasswd")
local smbpasswd_status = os.execute("printf '"..txt.."\n"..txt.."\n' | sudo smbpasswd -a we")
local hotspotpasswd_status;
local fd = io.open("home/we/norns/.system.hotspot_password", "w+")
if fd then
io.output(fd)
io.write(txt)
io.close(fd)
hotspotpasswd_status = true
end
if chpasswd_status then print("ssh password changed") end
if smbpasswd_status then print("samba password changed") end
if hotspotpasswd_status then print("hotspot password changed, toggle WIFI off/on to take effect") end
elseif string.len(txt) <= 8 then
print("!! password must be at least 8 characters !!")
print("!! password has not been changed !!")
elseif string.len(txt) > 64 then
print("!! password cannot be longer than 63 characters !!")
print("!! password has not been changed !!")
end
if chpasswd_status then print("ssh password changed") end
if smbpasswd_status then print("samba password changed") end
if hotspotpasswd_status then print("hotspot password changed, toggle WIFI off/on to take effect") end
end
_menu.set_page("SYSTEM")
end
Expand Down