CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
HELP with password .cgi

 



jami
New User

Apr 5, 2007, 3:51 PM

Post #1 of 7 (879 views)
HELP with password .cgi Can't Post

Hey all,

Is anyone able to help me create a password login using perl .cgi where the .cgi file checks a .txt file for validating the username and password...???


KevinR
Veteran


Apr 5, 2007, 3:52 PM

Post #2 of 7 (877 views)
Re: [jami] HELP with password .cgi [In reply to] Can't Post

what have you got done so far?
-------------------------------------------------


jami
New User

Apr 5, 2007, 3:59 PM

Post #3 of 7 (876 views)
Re: [KevinR] HELP with password .cgi [In reply to] Can't Post

http://planetvenus.massey.ac.nz/~jnnilsso/scripts/assignment1/assignment1.html created that...and created a file it goes to but something is not right...I am very new to this and know what I have to achieve but very confused as to how to get there....i just really want to finish it, its driving me crazy!!!...could I send you my brief??



#! /usr/bin/perl
print "Content-type: text/html\n\n";

#! /usr/bin/perl
print "Content-type: text/html\n\n";

if ($ENV{"REQUEST_METHOD"} eq "POST") {
read(STDIN, $datastring, $ENV{"CONTENT_LENGTH"});
}
elsif (exists $ENV{"REQUEST_METHOD"}) { # data from GET transaction (or HEAD or other)
$datastring = $ENV{"QUERY_STRING"};
}
else {
print "Offline execution detected\n";
print "Please enter some data.\n";
$datastring = <>;
chomp $datastring;
print "== data accepted == HTML output follows ==\n\n";
}


$dataDir = ""; # For simplicity (and portability) the data is in
# the same directory as this program
# Ideally, a secure data directory should be above
# the public part of the directory tree.

###app logic###################################################
If($formHash{"request"} eq "initial_logon") {
&initial_logon;
}
elsif($formHash{"request"} eq "logon_page") {
&logon_page;
}
else {
&assignment1.2.html;
}
###end app logic################################################





#################################################################
sub initial_logon {
my $result = &logon("$dataDir"."password.txt", $formHash{"user"}, $formHash{"pass"});
if($result ne "yes") {
&logon_page($result);
exit;
}
$sessionID = &get_long_id($stateDir,$cache_limit,$file_life_span);
%stateHash = ("user"=>$formHash{"user"}, "access"=>"admin");
&write_state($stateDir, $sessionID, %stateHash);
&add_user_page("You are now logged in.");
}

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

#################################################################
# end app logic functions
# begin toolkit functions
#################################################################
#################################################################

#################################################################
sub logon {
my($file, $alleged_user, $alleged_pass) = @_;
my($user, $pass, $line);

open(PASS, $file) or &errorPage("Failure to access user/pass info.");
while($line = <PASS>) {
chomp $line;
if($line ne ""){ ### precaution only ###
($user, $pass) = split(/:/, $line, 2);
if(lc $alleged_user eq lc $user) {
if($alleged_pass eq $pass) {
close(PASS);
return "yes";
}
else {
close(PASS);
return "Invalid password.";
}
}
}
}
close(PASS);
return "Invalid user.";
}

#################################################################
sub errorPage {
my $message = $_[0]; # optional message parameter

print<<ALL;
<html><head><title>Server Error</title></head><body>
<h2>Server Error Encountered</h2>
$message

If the problem persists, please notify the <a href="mailto:admin\@uweb.edu">webmaster</a>.
</body></html>
ALL

exit; # terminate program since failure to open data file
}


KevinR
Veteran


Apr 5, 2007, 4:12 PM

Post #4 of 7 (873 views)
Re: [jami] HELP with password .cgi [In reply to] Can't Post

Please do not send me your brief. "Something is no right" is quite vague. A very quick glance spotted this syntax error:

If($formHash{"request"} eq "initial_logon") {

If should be "if":

if($formHash{"request"} eq "initial_logon") {
-------------------------------------------------


jami
New User

Apr 5, 2007, 4:21 PM

Post #5 of 7 (872 views)
Re: [KevinR] HELP with password .cgi [In reply to] Can't Post

ok cheers...it still not working still getting this error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.More information about this error may be available in the server error log.

Apache/2.0.55 (Red Hat) Server at it004150.massey.ac.nz Port 80


KevinR
Veteran


Apr 5, 2007, 7:18 PM

Post #6 of 7 (866 views)
Re: [jami] HELP with password .cgi [In reply to] Can't Post

this looks wrong:

&assignment1.2.html;

I don't think a function name can contain dots in it but I'm not sure. But there is no function with that name in the code you posted so this is part of a larger script I assume.
-------------------------------------------------


hacker01
Novice

Apr 12, 2007, 9:46 AM

Post #7 of 7 (835 views)
Re: [jami] HELP with password .cgi [In reply to] Can't Post

You could just use .htaccess and make it very simple.

If you use your method, you will have to integrate the code into every program to allow access to the program and there is no way to protect standard files unless they are delivered via a program.

take a lok at
http://bumblebeeware.com/password/

It is a simple .htaccess script in perl that will make passwords easy as pie.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives