Globally reduce copyright headers
[project/luci.git] / modules / luci-mod-admin-mini / luasrc / model / cbi / mini / passwd.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
3 -- Licensed to the public under the Apache License 2.0.
4
5 f = SimpleForm("password", translate("Admin Password"), translate("Change the password of the system administrator (User <code>root</code>)"))
6
7 pw1 = f:field(Value, "pw1", translate("Password"))
8 pw1.password = true
9 pw1.rmempty = false
10
11 pw2 = f:field(Value, "pw2", translate("Confirmation"))
12 pw2.password = true
13 pw2.rmempty = false
14
15 function pw2.validate(self, value, section)
16         return pw1:formvalue(section) == value and value
17 end
18
19 function f.handle(self, state, data)
20         if state == FORM_VALID then
21                 local stat = luci.sys.user.setpasswd("root", data.pw1) == 0
22                 
23                 if stat then
24                         f.message = translate("Password successfully changed")
25                 else
26                         f.errmessage = translate("Unknown Error")
27                 end
28                 
29                 data.pw1 = nil
30                 data.pw2 = nil
31         end
32         return true
33 end
34
35 return f