#!/usr/bin/perl -w
use strict;
# Sample code snippt for a two-factor auth custom trigger
# script for a Perforce Helix server.
# Basic idea: Train users to enter token/password as one
# string where the first 6 digits are presumed to be the
# token, and whatever is left is the user password.
# The Peforce Server will prompt the user with 'Enter password:',
# this script picks up from there and reads user input.
## Read user name from command line arguments
my $UserName = shift @ARGV;
## Get password from the user on the command line.
my $UserPassword = <STDIN>;
chomp $UserPassword;
## Split out six-digit token.
my $Token = substr $UserPassword, 0, 6;
my $Password = substr $UserPassword, 6;
# Remove this line from a real version ...
print ("DEBUG: Token: $Token\nPassword: $Password\n");
## Verify token and password
my $Valid = 1;
### Take what we got from the user and feed it to the
### authentication system to see if it likes it.
unless($Valid) {
die "\nInvalid authentication attempt";
}
exit 0;