summaryrefslogtreecommitdiffstats
path: root/password-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'password-model.lua')
-rw-r--r--password-model.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/password-model.lua b/password-model.lua
index 33dffbd..90fa50d 100644
--- a/password-model.lua
+++ b/password-model.lua
@@ -1,6 +1,7 @@
-- password model methods
module (..., package.seeall)
strsplit = require "split"
+require "fs"
-- no initializer in model - use controller.init for that
@@ -17,3 +18,21 @@ get = function (self)
return (cfe{value=status, name="password"})
end
+--setup so that it will compare password input
+set = function (self, cmd1, cmd2)
+ if cmd1 ~= cmd2 then report = "Invalid or non matching password. Try again"
+ else
+ command = "/usr/bin/cryptpw" .. " " .. cmd1
+ f = io.popen(command)
+ c = f:read("*l")
+ f:close()
+ --this is hardcoded for root should be easy to change
+ newpass = "root:" .. c
+ t = fs.search_replace("/etc/shadow", "root:[!%w%$%/%.]+", newpass)
+ fs.write_file("/etc/shadow", fs.ipairs_string(t))
+ report = "Success. New password set."
+ end
+ return( cfe{value=report, name="report"})
+end
+
+