Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log in Script can't get it to work

Status
Not open for further replies.

madaxe

Technical User
Dec 21, 2004
44
US
Hi all i have been working on this for a few weeks no i got to the point where it worked with any user name but the password had to be correct, so now i want the user name to be checked as well but i can get it to work i know im close but im really stuck code to follow....PLEASE HELP....im going insane...also trying to get cookies to work so i can track user name from page to page and only give user specific info..


#!/Perl/bin/perl

# Address to this script.
$thisscript = "LOGIN.cgi";


# Page that the users should be sent to when they put in the correct
# password.
$forward = "../leaderboard.htm";

# Password required to login.
$userlist = "info.dat";



# Do you wish to log logins? (1/0)
# LOG file is NOT auto cleared. You will have to edit it by hand. If you
# delete it, remember to chmod the new file 777 when you re-make it.
$log = 1;

#Ask for name? (Will be logged.)
$name = 1;

#Ask for an e-mail address? (Will be logged.)
$email = 1;

#Ask for New Player Name? (Will be logged.)
$player = 1;



# What is the address to the log file? (Remember to create the file)

$log_file = "../LOGS/login_log.cgi";


# Path to your system's date program for logging.
$date_prog = "/bin/date";


#Name of the page that you are logging into.
$pagename = "GOLF";

# Settings for login page colors.
$text = "yellow";
$link = "blue";
$vlink = "blue";
$bgcolor = "blaCK";


##########################################################################
#
# DO NOT EDIT PAST THIS POINT WITHOUT PERMISSION.
#
##########################################################################



$date = `$date_prog '+%D %H:%M:%S'`;
%in = &getcgi;

##########################################################################

print "Content-type: text/html\n\n";

open (USERLIST, "$userlist") or &dienice("$userlist: $! \n");
@userlist = <USERLIST>;
close (USERLIST);


foreach my $dataline (@userlist) {
chomp ($dataline);
my ($username, $password) = split(/\|/, $dataline);
}
if ($in{'name'} ne $username) {

&print_login;
exit;
}

if ($in{'pass'} ne $password) {

&print_login;
exit;
}

if ($log == 1) {
if (($name == 1) && ($in{'name'} eq "")) {
&error("name");
}
if (($email == 1) && ($in{'email'} eq "")) {
&error("E-Mail address");
}
if (($player == 1) && ($in{'player'} eq "")) {
&error("PLAYER");
}
unless ($in{'email'} =~ m/\@/i) {
if ($email == 1) {
&error("correct e-mail address");
}
}

if (! -e "$log_file") {
open(FILE, ">$log_file");
print FILE "File START $date\n";
close(FILE);
}

##########################################################################
#
# WRITES INFO TO TEXT FILE
#
##########################################################################


open(FILE, ">>$log_file");


print FILE "#####################################################\n";



if ($name == 1) {
print FILE " Name: $in{'name'}\n";
}
if ($email == 1) {
print FILE " E-mail: $in{'email'}\n";
}
if ($player == 1) {
print FILE " PLAYER: $in{'player'}\n";
}


print FILE "#####################################################\n";


close(FILE);
}
##########################################################################


print "<html><head><META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0;URL=$forward\"></head></html>\n";
print "<a href=\"$forward\">Click here to contine!</a>";

sub print_login {
print <<"html";
<html><head><title>Login</title></head>

<body bgcolor=$bgcolor text=$text link=$link vlink=$vlink>


<div style='position: absolute; top: 30; left: 485;'><font size=5><b><u>WELCOME TO FANTASY $pagename</u></b></font></div>
<div style='position: absolute; top: 60; left: 585;'><font size=5><b><u>PLEASE LOG IN.</u></b></font></div>
<span style="position: absolute; left: 0; top: 0; z-index: -10"><img border="0" src="../IMAGES/backgroundpart.jpg" width="459" height="336"></span>
<span style="position: absolute; left: 370; top: 0; z-index: -10"><img border="0" src="../IMAGES/top.jpg" width="606" height="56"></span>
<span style="position: absolute; left: 370; top: 350"><img border="0" src="../IMAGES/bottom.jpg" width="606" height="55"></span>
<span style="position: absolute; left: 370; top: 55"><img border="0" src="../IMAGES/frameleft.jpg" width="65" height="295"></span>
<span style="position: absolute; left: 911; top: 55"><img border="0" src="../IMAGES/frameright.jpg" width="65" height="295"></span>



<form method=post action=\"$thisscript\">
html


if ($name == 1) {
print " <div style='position: absolute; top: 170; left: 530;'>
<b>Name: </b>
<input type=text name=name size=30>
</div><br>
\n";
}




if ($email == 1) {
print "
<div style='position: absolute; top: 200; left: 468;'>
<b>E-mail Address: </b>
<input type=text name=email size=30>
</div><br>
\n";
}






if ($player == 1) {
print "
<div style='position: absolute; top: 270; left: 426;'>
<b>Fantasy Player Name: </b>
<input type=text name=player size=30>
</div><br>
\n";
}



print <<"html";



<div style='position: absolute; top: 300; left: 507;'>
<b>Password: </b><input type=password name=pass>
<input type=submit value=Submit name=submit>
</div>

</form>
</body>
</html>
html
return 1;
}

##########################################################################


sub getcgi {
local($in, %in);
local($name, $value);

# If REQUEST_METHOD is POST, use CONTENT_LENGTH. Else, use QUERY_STRING.
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
if ($ENV{'CONTENT_TYPE'}=~ m#^application/x- {
read(STDIN, $in, $ENV{'CONTENT_LENGTH'});
}
}
else {
$in= $ENV{'QUERY_STRING'};
}
# Resolve and unencode name/value pairs into %in
foreach (split('&', $in)) {
s/\+/ /g;
($name, $value)= split('=', $_, 2);
$name=~ s/%(..)/sprintf("%c",hex($1))/ge;
$value=~ s/%(..)/sprintf("%c",hex($1))/ge;
$in{$name}.= $value;
}
return %in;
}

sub error {
local($error) = $_[0];
print <<"html";
<html><head<title>Error</title></head>
<body bgcolor=white>
<center><font size=5>Error</font><p><b>
You must enter a $error!
</body></html>
html
exit;
return 1;
}

sub dienice {
my($msg) = @_;
print "<h2>Error</h2>\n";
print $msg;
exit;
 
the specific piece i think is not working is as follows

if anybody wants to copy this for there own use have at it

MadAxe
##########################################################################

print "Content-type: text/html\n\n";

open (USERLIST, "$userlist") or &dienice("$userlist: $! \n");
@userlist = <USERLIST>;
close (USERLIST);


foreach my $dataline (@userlist) {
chomp ($dataline);
my ($username, $password) = split(/\|/, $dataline);
}
if ($in{'name'} ne $username) {

&print_login;
exit;
}

if ($in{'pass'} ne $password) {

&print_login;
exit;
}
 
TOTALLY REBUILT SCRIPT NOW IT WORKS


MadAxe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top