in reply to Using Unix passwd/shadow to authenticate in perl

Just a thought, but since I know RH7.2 includes the PAM (pluggable authentication module) system, you may want to take a look at Authen::PAM, a perl interface into the PAM. Just a thought... HTH.

  • Comment on Re: Using Unix passwd/shadow to authenticate in perl

Replies are listed 'Best First'.
Re: Re: Using Unix passwd/shadow to authenticate in perl
by bennomatic (Initiate) on Sep 26, 2003 at 16:51 UTC
    Thanks for the tip. I knew there was something called "PAM" that I needed to look for, but my initial searches yielded nothing, so I assumed I must have been starting with bad info. Thanks for the link.
      Authen::PAM won't help with shadow passwords. Root is the only user that can read /etc/shadow, so root is the only user that can verify password.

      The advantage of using PAM is that it handles all the mechanisms for authenticating users. It takes care of the encryption algorithms: crypt, MD5, etc. It also will handle users authenticated through LDAP, Samba, NIS, or something else.

        You can actually use pam to uthenticate as a normal user. You never get to see the encrypted password, but the pam lib tells you whether the password you are giving is right or not. Here is a quick example (cut & paste from the Authen::PAM perldocs):

        #!/usr/bin/perl -w use strict; use Authen::PAM; my $login_name = getpwuid($<); sub conversation { my @res; while ( @_ ) { my $msg_type = shift; my $msg = shift; my $ans = "put your password here"; push @res, (0,$ans); } push @res, PAM_SUCCESS(); return @res; } my $pamh; pam_start("passwd", $login_name, \&conversation, $pamh); print pam_authenticate($pamh); pam_end($pamh);
        The outcome changes depending on whether the password is correct.

        Cheers

        Antonio

        The stupider the astronaut, the easier it is to win the trip to Vega - A. Tucket
        OK, I'm confused. So if I use the AUTHEN::PAM module, I will or won't be able to authenticate users from a CGI script based on their UNIX account/password pairs? I don't actually care about direct access to the shadow file, as long as I can make those authentications...