-function user.checkpasswd(username, password)
- local account = user.getuser(username)
-
- if account then
- local pwd = account.passwd
- local shadowpw
- if #pwd == 1 then
- if luci.fs.stat("/etc/shadow") then
- if not pcall(function()
- for l in io.lines("/etc/shadow") do
- shadowpw = l:match("^%s:([^:]+)" % username)
- if shadowpw then
- pwd = shadowpw
- break
- end
- end
- end) then
- return nil, "Unable to access shadow-file"
- end
- end
-
- if pwd == "!" then
- return true
- end
- end
-
- if pwd and #pwd > 0 and password and #password > 0 then
- return (pwd == posix.crypt(password, pwd))
- end
+function user.checkpasswd(username, pass)
+ local pwe = nixio.getsp and nixio.getsp(username) or nixio.getpw(username)
+ local pwh = pwe and (pwe.pwdp or pwe.passwd)
+ if not pwh or #pwh < 1 or pwh ~= "!" and nixio.crypt(pass, pwh) ~= pwh then
+ return false
+ else
+ return true