summaryrefslogtreecommitdiffstats
path: root/password-model.lua
blob: 2f81bff97c5565d521e6ad6dff15e4c0500abe27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- password model methods
module (..., package.seeall)
require "format"

-- no initializer in model - use controller.init for that

get = function (self)
--hardcoded for root now	
	f = format.search_for_lines("/etc/shadow", "root:")
	temp = format.string_to_table(":", f)
	if temp[2] == "!" then
	status = "not set"
	else
	status = "set"
	end        
	f:close()	
	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