while ($new_remote = $sock->accept) {
$new_remote->autoflush(1);
print $new_remote "Welcome to MyListenSvc v$VERSION\r\n";
print $new_remote "Please enter your username: \r\n";
chomp ($usrname = <$new_remote>);
print $new_remote "Please enter your password: \r\n";
chomp ($password = <$new_remote>);
while (length($password) < 8) {
print $new_remote "Password is too short.(Must be at least 8 characters).\r\n";
print $new_remote "Please enter your password: \r\n";
chomp ($password = <$new_remote>);
}
unless (&AuthUser($usrname, $password)) {
print $new_remote "Authentication Errors - Check your username and password.\n";
&Update_Log("... Login FAILED\n");
close ($new_remote);
last;
} else {
print $new_remote "Authenticated Successfully ";
print $new_remote "(Type help for a list of commands)\r\n";
print $new_remote "Command: ";
$sel->add($new_remote) if ($new_remote);
last;
}
}
####
sub AuthUser
{
my ($user, $pass) = @_;
$user = substr($user, 0, -1);
$pass = substr($pass, 0, -1);
&Update_Log("Attempting to login as $usrname with $password... ");
$auth_rc = 0;
my $cipher = Crypt::CBC->new( { 'key' => "$pass",
'cipher' => 'Blowfish',
'iv' => '$KJh#(}q',
'regenerate_key' => 0, # default true
'padding' => 'space',
'prepend_iv' => 0
});
my $ciphertext = $cipher->encrypt("$user");
open PWD, "C:/MyListenSvc/bin/passwd" or return ($auth_rc);
while () {
if (m#\Q$ciphertext\E#) {
&Update_Log("... Login OK\n");
$auth_rc = 1;
last;
}
}
close (PWD);
return ($auth_rc);
}
####
$user = substr($user, 0, -1);
$pass = substr($pass, 0, -1);