#
# CVS Info: $Id: passwd.pl,v 1.1.1.1 2000/03/31 19:18:59 apendlet Exp $
# Filename: perl/password.pl
#   Author: Adam H. Pendleton
#

require 'config/sara.cf';

# When passed a username, this will return the password
sub get_password {
    local($username) = shift;

    open(PWDFILE, "$password_file") or die "Can't open $password_file: $!";

    while(<PWDFILE>) {
        ($user, $pass) = split(/:/);
        if ($username eq $user) {
            return $pass;
        }
        else {
            return "";
        }
    }
}

# This checks the passed username/password pair
sub validate_user {
    local($username, $password) = @_;

    open(PWDFILE, "$password_file") or die "Can't open $password_file: $!";

    while(<PWDFILE>) {
        ($user, $pass) = split(/:/);
        chomp $user;
        chomp $pass;
        if ($username eq $user) {
            if (crypt($password, $pass) eq $pass) {
                return 1;
            }
            else {
                return 0;
            }
        }
    }
    return 0;
}

1;
