in reply to getpwnam() password

Well if you are trying to authenticate users this will work. This is the code I have used for a web front end. It is taken out of the documentation.

sub check_pass {
  sub my_conv_func {
    my @res; while ( @_ ) {
    my $code = shift;
    my $msg = shift;
    my $ans = "";

    $ans = $userid if ($code == PAM_PROMPT_ECHO_ON() );
    $ans = $pass if ($code == PAM_PROMPT_ECHO_OFF() );

    push @res, PAM_SUCCESS();
    push @res, $ans;
    }
    push @res, PAM_SUCCESS();
    return @res;
   }

  ref($pamh = new Authen::PAM($service, $userid,\&my_conv_func)) || die "Error code $pamh during PAM init!";

  $ret=$pamh->pam_authenticate;

  if($ret ne 0) {
    print header, start_html("Password Change");
    print("Please enter your correct UserID Password");
    print end_html; die;
  }