#!/usr/bin/perl -w

print <<"END"

Temporal Vortex BBS Software
Written by Jeff Ledger & Matthew Martin
Copyright 2000 GNU License


END



if (open(MYFILE, "preuser.ans")); {
    while(<MYFILE>) {
	print;
    }
}

while(1) {
    
    $allow = 0;
    $realpass = '';

    print "Enter your login name or NEW: ";
    chomp($username = <STDIN>);
    if($username eq '') { $username = 'idiot_fool_moron'; }
    if($username eq 'NEW') { exec "./newuser"; }
    if($username eq 'new') { exec "./newuser"; }
    print "\n";
    print "Enter your password: ";
    chomp($password = <STDIN>);

    open(PASSWD, "tvpl") || die("Couldn't open tvpl: $!\n");

    while(<PASSWD>) {
	if(/^$username\s/i) {
	    ($realpass) = /^$username\s*(\w.*)/i;
	    if($password eq $realpass) {
		$allow = 1;
	    }
	}
    }
    
    if($allow == 0) {
	print "Login failed. Bad username and/or password.\n\n";
    }
    
    else {
	last;
    }
    
}

$username =~ s/\s/_/;

## WRITE LOGIN INFO TO LOGIN STATS FILE ##

open (FILE,">lastlogin");
flock (FILE, 2);
print FILE "$username";
flock (FILE, 8);
close (FILE);

## Inform Whoever is sitting at console ##
system ("echo -e ' ' > /dev/console");
system ("echo -e '$username is logging in...' > /dev/console");
	 
exec "./main $username";
