Use getent instead of /etc/passwd.