Internet Programming w/JAVA

CS Account Verification

Using getpwnam()


The C library provides a function called pwnam(string name) which searches through the /etc/passwd (or its NIS equiv. in the case of CS) for the given username. It returns all information contained in /etc/passwd for that user. In PERL, the same function exists and returns an array containing the following:

The verify_vote subroutine below demonstrates usage of getpwnam():

#######
## int verify_vote( login_name, last_name )  !! login_name is case sensitive
##                                           !! side effect: sets $reason
#######
sub verify_vote {
    local($id, $lastname) = @_;
    local($name, $passwd, $uid, $age,
          $comment, $gecos, $dir, $shell) = getpwnam($id);

    if(!$name) {
        $reason = "No such account";
        return 0;
    } elsif($gecos =~ /\b$lastname/i) {
        return 1;
    }
    $reason = "Your account status could not be verified. "
            . "Check last name and/or username."
    return 0;
}

Advantages

Disadvantages


Andrew T. Graham (atgraham@cs.millersv.edu)
URL: http://cs.millersv.edu/~atgraham/vote/getpwnam.html