passwd.lua 922 B

1234567891011121314151617181920212223242526272829303132333435
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
  3. -- Licensed to the public under the Apache License 2.0.
  4. f = SimpleForm("password", translate("Admin Password"), translate("Change the password of the system administrator (User <code>root</code>)"))
  5. pw1 = f:field(Value, "pw1", translate("Password"))
  6. pw1.password = true
  7. pw1.rmempty = false
  8. pw2 = f:field(Value, "pw2", translate("Confirmation"))
  9. pw2.password = true
  10. pw2.rmempty = false
  11. function pw2.validate(self, value, section)
  12. return pw1:formvalue(section) == value and value
  13. end
  14. function f.handle(self, state, data)
  15. if state == FORM_VALID then
  16. local stat = luci.sys.user.setpasswd("root", data.pw1) == 0
  17. if stat then
  18. f.message = translate("Password successfully changed")
  19. else
  20. f.errmessage = translate("Unknown Error")
  21. end
  22. data.pw1 = nil
  23. data.pw2 = nil
  24. end
  25. return true
  26. end
  27. return f