libs/sys: fix login with empty password after previous commit

This commit is contained in:
Jo-Philipp Wich 2012-06-27 14:11:48 +00:00
parent b1617b3718
commit e2dd594c38

View file

@ -596,13 +596,14 @@ user.getuser = nixio.getpw
--- Retrieve the current user password hash. --- Retrieve the current user password hash.
-- @param username String containing the username to retrieve the password for -- @param username String containing the username to retrieve the password for
-- @return String containing the hash or nil if no password is set. -- @return String containing the hash or nil if no password is set.
-- @return Password database entry
function user.getpasswd(username) function user.getpasswd(username)
local pwe = nixio.getsp and nixio.getsp(username) or nixio.getpw(username) local pwe = nixio.getsp and nixio.getsp(username) or nixio.getpw(username)
local pwh = pwe and (pwe.pwdp or pwe.passwd) local pwh = pwe and (pwe.pwdp or pwe.passwd)
if not pwh or #pwh < 1 or pwh == "!" or pwh == "x" then if not pwh or #pwh < 1 or pwh == "!" or pwh == "x" then
return nil return nil, pwe
else else
return pwh return pwh, pwe
end end
end end
@ -611,9 +612,9 @@ end
-- @param pass String containing the password to compare -- @param pass String containing the password to compare
-- @return Boolean indicating wheather the passwords are equal -- @return Boolean indicating wheather the passwords are equal
function user.checkpasswd(username, pass) function user.checkpasswd(username, pass)
local pwh = user.getpasswd(username) local pwh, pwe = user.getpasswd(username)
if pwh then if pwe then
return (nixio.crypt(pass, pwh) == pwh) return (pwh == nil or nixio.crypt(pass, pwh) == pwh)
end end
return false return false
end end