#!/usr/bin/perl -w use strict; $|++; #------------------------------------------------------------------------------ # Basic Auth and entitlement function set. Read perldoc -f crypt for a tad # more information on crypt and salt (contains a nice function for random # salt). Then go on and read many more tomes to get a tad more information :) #------------------------------------------------------------------------------ my ( $username, $passwd ) = @ARGV; if ( my $permissions = &check_passwd( $username, $passwd ) ) { print "$username is $permissions\n"; } else { print "authentication failed\n"; } ## # check_passwd( $username, $password ); # # returns group or permissions or whatever you have in the third column of your # passwd file if username and password match # sub check_passwd ($$) { my ($input_username, $input_passwd) = @_; while () { my ($username, $crypted_passwd, $permissions) = split ':'; next unless $input_username eq $username; my $crypted_input_passwd = crypt($input_passwd, $crypted_passwd); if ( $crypted_input_passwd eq $crypted_passwd ) { chomp( $permissions ); return $permissions; } } return; } ## # DATA file description and data (with unencrypted passwords, for testing) # # username:passwd:permissions # nob:bob:god # rim:tim:angel # hal:kal:devil ## __DATA__ nob:a1ni5aPmumc2E:god rim:jZR4taPdoUdwA:angel hal:0ZYFuJV/xWRvc:devil