LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2007, 07:57 AM   #16
mobs99
Member
 
Registered: Oct 2007
Posts: 30

Original Poster
Rep: Reputation: 15

This is the page i called register.pl

Quote:
#!/usr/bin/perl

$cookiedata = $ENV{'HTTP_COOKIE'};

@cookies = split(/;/,$cookiedata);

foreach $c (@cookies)
{
($cname,$cvalue) = split(/=/,$c);
if ($cname eq 'mode')
{
$mode = $cvalue;
}
}

if ($mode eq "yes")
{
print headers("no");
print getWelcomeHTML();
}

elsif ($mode eq "no")

{
print headers("yes");
print getNotWelcomeHTML();
}

else

{
print headers("yes");
print getErrorHTML();
}

sub headers
{
$cookieval = shift @_;
# don't put any attributes, so will be session cookie with
# default values for domain and path
return "Set-Cookie: mode=$cookieval\nContent-Type: text/html\n\n";
}


sub getNotWelcomeHTML
{
print <<END;

<html>

<head>
<title>Internet Application Programming</title>
</head>

<body bgcolor="lightyellow"><center><u>Registration facility</center></u></body><br />

<form action="check.pl" method="post">

Enter Name<br>
<input type="text" size=20 value="" name="fname"/><br />
<br />


Enter Surname<br>
<input type="text" size=20 value="" name="sname"/><br />
<br />


Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
<br />


Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
<br />


Date Of Birth<br>
<input type="text" size=20 value="" name="DOB"/><br />
<br />

<input type="submit" value="Send">
</form>
</body>
</html>


END
}

sub getWelcomeHTML
{
print <<END;
<html>

<head>
<title>Internet Application Programming</title>
</head>

<body bgcolor="lightyellow"><center><u>Login facility</center></u></body><br />

<form>
Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
</form><br />

<form>
Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
</form><br />


<input type="submit" value="Login">

</body>
</html>
END

}

sub getErrorHTML
{
print <<END;
<html>

<head>
<title>Internet Application Programming</title>
</head>

<body bgcolor="lightyellow"><center><u>LOGIN</center></u></body><br />

<form>
Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
</form><br />

<form>
Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
</form><br />


<input type="submit" value="Login">

</body>
</html>
END

}
and this is the page where it checks it which is called check.pl

Quote:
#!/usr/bin/perl

$length = $ENV {'CONTENT_LENGTH'};
read (STDIN,$data,$length);



($fname, $lname, $username, $password, $dob ) = split(/&/,$data);
($firstkey, $fname) = split(/=/,$fname);
($firstkey, $sname) = split(/=/,$lname);
($firstkey, $Username) = split(/=/,$username);
($firstkey, $Password) = split(/=/,$password);
($firstkey, $DOB) = split(/=/,$dob);


print "Content-Type: ", "text/html\n\n";
print "First name: ", $fname, "\n";
print "Last name: ", $sname, "\n";
print "User name: ", $Username, "\n";
print "Password: ", $Password, "\n";
print "D.O.B: ", $DOB, "\n";


$file = "cookie.txt";
if (open (OUTFILE,"> $file"))
{
print OUTFILE "$fname - $sname - $Username - $Password - $DOB\n";
}
 
Old 11-19-2007, 07:58 AM   #17
mobs99
Member
 
Registered: Oct 2007
Posts: 30

Original Poster
Rep: Reputation: 15
basically ive got it reading what on the registration page and putting it in a txt file... but i need it to read of the txt page in the login page so itl allow the user to log in.. hope it makes sense
 
Old 11-19-2007, 03:18 PM   #18
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Your form(s) have a couple of problems. You probably want only only one form, with multiple input widgets, instead of each widget in its own form. Secondly, the form should have an action attribute that points to your CGI.
See http://www.w3.org/TR/html4/interact/forms.html for information on this. Normally, each form you create should specify a CGI which responds to submittal of the form.
If you want people to help you, please help them by posting source code using [C O D E] tags to preserve formatting.
--- rod.
 
Old 11-19-2007, 04:25 PM   #19
mobs99
Member
 
Registered: Oct 2007
Posts: 30

Original Poster
Rep: Reputation: 15
ok what ive done now is ive created 3 files..
1 is register.pl this actually deals with the registration of the user. after the user registers hel click submit button and with the check.pl file it will store the details into a file called default.db (already done)

loginfinal.pl with this will read off the default.db file where the details are stored and log the user in if he has entered the login details correctly this part i need help with reading of the db file..

and the other is check.pl which stores the details onto the default.db file

this is the register.pl file

Code:
#!/usr/bin/perl

$cookiedata = $ENV{'HTTP_COOKIE'};

@cookies = split(/;/,$cookiedata);

foreach $c (@cookies) 
{
    ($cname,$cvalue) = split(/=/,$c);
    if ($cname eq 'mode') 
    {
	$mode = $cvalue;
    }
}

if ($mode eq "yes") 
{
    print headers("no");
    print getWelcomeHTML();
}

elsif ($mode eq "no") 

{
    print headers("yes");
    print getNotWelcomeHTML();
}

else

{
    print headers("yes");
    print getErrorHTML();
}

sub headers 
{
    $cookieval = shift @_;
    # don't put any attributes, so will be session cookie with
    # default values for domain and path
    return "Set-Cookie: mode=$cookieval\nContent-Type: text/html\n\n";
}


sub getNotWelcomeHTML 
{
    print <<END;
    
    <html>
	  
	<head>
	<title>Internet Application Programming</title>
	</head>
	
	<body bgcolor="lightyellow"><center><u>Registration facility</center></u></body><br />
	
	<form action="check.pl" method="post">
	
	Enter Name<br>
	<input type="text" size=20 value="" name="fname"/><br />
	<br />
	
	
	Enter Surname<br>
	<input type="text" size=20 value="" name="sname"/><br />
	<br />
	
	
	Enter Username<br>
	<input type="text" size=20 value="" name="username"/><br />
	<br />
	
	
	Enter Password<br>
	<input type="password" size=20 value="" name="password"/><br />
	<br />
	
	
	Date Of Birth<br>
	"Please enter D.O.B in the following format ddmmyyyy"<br />
	<input type="text" size=20 value="" name="DOB"/><br />
	<br />
	
	<input type="submit" value="Send" "login.pl">
	</form>
	If you are already registerd please click on the following link to log in!!!!!
	<a href="http://localhost/net/loginfinal.pl">click here</a>
	</body>
	</html>
	
	
END
}
]

Code:
#!/usr/bin/perl    

$length = $ENV {'CONTENT_LENGTH'};
    read (STDIN,$data,$length);


    
($fname, $lname, $username, $password, $dob ) = split(/&/,$data);
($firstkey, $fname) = split(/=/,$fname);
($firstkey, $sname) = split(/=/,$lname);
($firstkey, $Username) = split(/=/,$username);
($firstkey, $Password) = split(/=/,$password);
($firstkey, $DOB) = split(/=/,$dob);


print "Content-Type: ", "text/html\n\n";
print "First name: ", $fname, "\n";
print "Last name: ", $sname, "\n";
print "User name: ", $Username, "\n";
print "Password: ", $Password, "\n";
print "D.O.B: ", $DOB, "\n";


$file = "default.db";
if (open (OUTFILE,"> $file"))
{
  print OUTFILE "$fname - $sname - $Username - $Password - $DOB\n";
}
Code:
#!/usr/bin/perl

use strict;
use warnings 'all';

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);

#############################
my $header = "header.txt";
my $footer = "footer.txt";
my $pw = "demo";
############################

my $cookiename = "linkpop";
my $pass= param('pass');
my $tasty = cookie($cookiename);


my $edit = url_param("edit");
my $rem  = url_param("rem");

use POSIX;
use DB_File;
my %default;
my $default = "default.db";                 # location of database



###############################################################################################################
# COOKIE CHECKING
###############################################################################################################
# First check if we saved a cookie last time
if($tasty)
{
print header(-expires=>'now'),
start_html("Script name");

&processing;

print end_html;
exit;
}
########################################################################################################
# Password checking
########################################################################################################
unless ($pass eq $pw)
{
    print header(-expires=>'now'), start_html("Login");
    
    print <<"FORM";
    <form action="" method="POST">
	<table width="296" border="2" align="center" cellpadding="2" cellspacing="0" bordercolor="#0033FF">
	<tr>
	<td width="286"><table width="100%" height="100%" border="0" align="center" cellpadding="2">
	<tr bgcolor="#0099FF">
	<td colspan="2"><div align="center">User Login </div></td>
	</tr>
	<tr>
	<td width="65">Username:</td>
	<td width="196"><input name="user" type="username" id="user"></td>
	</tr>
	<tr>
	<td width="65">Password:</td>
	<td width="196"><input name="pass" type="password" id="pass"></td>
	</tr>
	<tr>
	<td colspan="2"><div align="center">
	<input type="submit" name="Submit" value="Submit">
	</div></td>
	</tr>
	</table>
	<div align="center"></div>
     <div align="center"></div>
   <div align="center"></div></td>
 </tr>
</table><tr>
	<a href="http://localhost/net/register.pl">click here to register</a>
</tr>
</form>

FORM

   if (param())
   {
     if ($pass ne $pw)
     {
   
        print "<b>Mobin says wrong password asshole!</b>";
        exit;
     }
   }
   exit;
   }

########################################################################################################
# Cookie setting
########################################################################################################
my $cookie = cookie(
   -NAME=> $cookiename,
   -VALUE=> $pass,
   );
   print header(-COOKIE => $cookie, -expires=>'now');
   print start_html("");
 
Old 11-19-2007, 08:56 PM   #20
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Will this ever be a really large (membership greater then, say 100,000) site? If not, I suggest simply using a text flatfile database. Easier, faster.
--- rod.
 
Old 11-20-2007, 04:34 AM   #21
mobs99
Member
 
Registered: Oct 2007
Posts: 30

Original Poster
Rep: Reputation: 15
no it wont

so
Code:
use POSIX;
use DB_File;
my %default;
my $default = "default.db
from that would it be as easy as saying ill change DB_FILE to test file and default.db to default.txt lets say
or wil i av to change everything???
 
Old 11-20-2007, 07:21 AM   #22
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Just read and write files. Use some simple locking mechanism (retrofit this once you have basic read/write access working).
Or study the docs on DB_file, and just figure out how to use it. Do that offline for easier testing.
--- rod.
 
Old 11-20-2007, 01:23 PM   #23
mobs99
Member
 
Registered: Oct 2007
Posts: 30

Original Poster
Rep: Reputation: 15
aint got a clue what that meant mate sorry
 
Old 11-20-2007, 02:27 PM   #24
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You are storing a 'database' that evidently consists of one table. Since the only thing that a database manager contributes to this scenario is overhead and potentially file &/or record locking, why not store your data in a simple text file? When a user registers, add a record to the file. When a registered user logs in, lookup the password and other info from the file. You can easily read and parse a file of a few thousand records without significant delay on each login or registration.
--- rod.
 
Old 11-20-2007, 04:06 PM   #25
mobs99
Member
 
Registered: Oct 2007
Posts: 30

Original Poster
Rep: Reputation: 15
ok ive reverted back to my 1st 1. where it actually stores the data in a txt file.. now ive got the login page all done but i just need to read of that text file when i click submit on the login page...
how do i make it read of the txt file..
many thanks for u help

Code:
#!/usr/bin/perl

$length = $ENV {'CONTENT_LENGTH'};
read (STDIN,$data,$length);



($fname, $lname, $username, $password, $dob ) = split(/&/,$data);
($firstkey, $fname) = split(/=/,$fname);
($firstkey, $sname) = split(/=/,$lname);
($firstkey, $Username) = split(/=/,$username);
($firstkey, $Password) = split(/=/,$password);
($firstkey, $DOB) = split(/=/,$dob);


print "Content-Type: ", "text/html\n\n";
print "First name: ", $fname, "\n";
print "Last name: ", $sname, "\n";
print "User name: ", $Username, "\n";
print "Password: ", $Password, "\n";
print "D.O.B: ", $DOB, "\n";


$file = "cookie.txt";
if (open (OUTFILE,"> $file"))
{
print OUTFILE "$fname - $sname - $Username - $Password - $DOB\n";
}
Code:
#!/usr/bin/perl

$cookiedata = $ENV{'HTTP_COOKIE'};

@cookies = split(/;/,$cookiedata);

foreach $c (@cookies)
{
($cname,$cvalue) = split(/=/,$c);
if ($cname eq 'mode')
{
$mode = $cvalue;
}
}

if ($mode eq "yes")
{
print headers("no");
print getWelcomeHTML();
}

elsif ($mode eq "no")

{
print headers("yes");
print getNotWelcomeHTML();
}

else

{
print headers("yes");
print getErrorHTML();
}

sub headers
{
$cookieval = shift @_;
# don't put any attributes, so will be session cookie with
# default values for domain and path
return "Set-Cookie: mode=$cookieval\nContent-Type: text/html\n\n";
}


sub getNotWelcomeHTML
{
print <<END;

<html>

<head>
<title>Internet Application Programming</title>
</head>

<body bgcolor="lightyellow"><center><u>Registration facility</center></u></body><br />

<form action="check.pl" method="post">

Enter Name<br>
<input type="text" size=20 value="" name="fname"/><br />
<br />


Enter Surname<br>
<input type="text" size=20 value="" name="sname"/><br />
<br />


Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
<br />


Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
<br />


Date Of Birth<br>
<input type="text" size=20 value="" name="DOB"/><br />
<br />

<input type="submit" value="Send">
</form>
</body>
</html>


END
}

sub getWelcomeHTML
{
print <<END;
<html>

<head>
<title>Internet Application Programming</title>
</head>

<body bgcolor="lightyellow"><center><u>Login facility</center></u></body><br />

<form>
Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
</form><br />

<form>
Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
</form><br />


<input type="submit" value="Login">

</body>
</html>
END

}

sub getErrorHTML
{
print <<END;
<html>

<head>
<title>Internet Application Programming</title>
</head>

<body bgcolor="lightyellow"><center><u>LOGIN</center></u></body><br />

<form>
Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
</form><br />

<form>
Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
</form><br />


<input type="submit" value="Login">

</body>
</html>
END

}
 
Old 11-20-2007, 06:34 PM   #26
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Code:
    open( USERDB, "cookie.txt" );
    my @userDb = <USERDB>;
    close USERDB;
    foreach my $userRecord ( @userDb ){
        my ($fname,$sname,$Username,$Password,$DOB) = split / - /, $userRecord;
        #
        # validate user here....
        #
    }
Basic perl. No magic here.


--- rod.
 
Old 11-20-2007, 07:27 PM   #27
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
If you used CGI.pm, you wouldn't have to code all that HTML, the fns/methods do that for you (and safer).
also, why do you have the '$firstkey' attached to every field? If it's all one rec, just put it at the first field pt.
 
Old 11-21-2007, 05:36 PM   #28
mobs99
Member
 
Registered: Oct 2007
Posts: 30

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by theNbomr View Post
Code:
    open( USERDB, "cookie.txt" );
    my @userDb = <USERDB>;
    close USERDB;
    foreach my $userRecord ( @userDb ){
        my ($fname,$sname,$Username,$Password,$DOB) = split / - /, $userRecord;
        #
        # validate user here....
        #
    }
Basic perl. No magic here.


--- rod.
so rod will that code allow me to read of the txt file and log in??
can i ask what
Code:
USERDB
does??
 
Old 11-21-2007, 06:58 PM   #29
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
USERDB is a file handle: http://perldoc.perl.org/functions/open.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl CGI:Can't locate CGI.pm supermyself Programming 13 09-10-2007 07:22 AM
Setting up a registration website jwolter0 Linux - Server 3 09-05-2007 06:21 AM
Perl CGI login authentication jefflanam Linux - Security 1 06-08-2007 03:06 AM
CGI/Perl indienick Programming 2 03-06-2006 04:16 PM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 06:07 AM


All times are GMT -5. The time now is 02:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration