-- password model methods module (..., package.seeall) require ("fs") read_password = function() pw = {} pw.user = cfe({ label="User Name" }) pw.password = cfe({ label="Password" }) pw.password_confirm = cfe({ label="Password (confirm)" }) return cfe({ type="group", value=pw, label="System Password" }) end --setup so that it will compare password input update_password = function (pw) local success = true if pw.value.password.value == "" or pw.value.password.value ~= pw.value.password_confirm.value then pw.value.password.errtxt = "Invalid or non matching password" success = false end local filecontent = "\n"..fs.read_file("/etc/shadow") if pw.value.user.value == "" or not string.find(filecontent, "\n"..pw.value.user.value..":") then pw.value.user.errtxt = "Unknown user" success = false end if success then local f = io.popen("/usr/bin/cryptpw " .. pw.value.password.value) local newpass = f:read("*l") f:close() local new = string.gsub(filecontent, "(\n"..pw.value.user.value..":)[^:]*", "%1"..newpass) fs.write_file("/etc/shadow", string.sub(new, 2)) else pw.errtxt = "Failed to set password" end return pw end