1#!/usr/bin/env perl
2# Example script to check authentication on a RADIUS server
3use strict;
4use warnings;
5use Authen::Radius;
6
7my $verbose = 0;
8$verbose = 1 if (($ARGV[0] // '') eq '--verbose');
9
10STDOUT->autoflush(1);
11
12print "Make sure this machine is in your Radius clients file!\n";
13
14print "Enter hostname[:port] of your Radius server: ";
15chomp( my $host = <STDIN> );
16
17print "Enter shared-secret of your Radius server: ";
18chomp( my $secret = <STDIN> );
19
20print "Enter a username to be validated: ";
21chomp( my $user = <STDIN> );
22
23print "Enter this user's password: ";
24chomp( my $pwd = <STDIN> );
25
26my $r = Authen::Radius->new(
27            Host   => $host,
28            Secret => $secret,
29            Debug  => $verbose,
30        );
31
32Authen::Radius->load_dictionary();
33
34my $result = $r->check_pwd( $user, $pwd );
35if ($result) {
36    print "Accept\n";
37}
38elsif ($r->get_error() eq 'ENONE') {
39    print "Reject\n";
40}
41else {
42    print 'Error: ', $r->strerror(), "\n";
43    exit 1;
44}
45
46my @attributes = $r->get_attributes();
47foreach my $attr (@attributes) {
48    printf "%s %s = %s\n", $attr->{Vendor} // ' ', $attr->{Name}, $attr->{Value} // $attr->{RawValue};
49}
50