Lucas Leonardo wrote:

> I'am writing a program that need to verify a user password. Is there
> function call to retrieve a user password or fuction call to verify a
> user pasword?

The password hash can be obtained using getpwent, getpwnam or getpwuid
(or if you are using shadow passwords, getspent or getspnam).

To check a password, you use the crypt() function, and compare the
result against the password hash, e.g.

        #include <pwd.h>
        #include <crypt.h>
        
        static int
        check_passwd(const char *user, const char *passwd)
        {
                struct passwd *pw;
        
                pw = getpwnam(user);
                if (!pw)
                        return 0;       /* no such user */
        
                return (strcmp(pw->pw_passwd, crypt(passwd, pw->pw_passwd)) == 0);
        }

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to