SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old August 18th, 2000, 12:23 PM
Loki Loki is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Norman, OK, USA
Posts: 12 Loki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Loki
Hello All.

the following sub is for a simple login page, where a user has to enter their username and password. As it works now, it will verify that the password belongs to the username, but if no username is specified, it will go ahead and let anyone in, even if they enter an arbitrary password (it does send them to a specific user account).
The question, what do I add to this sub to make it confirm that a username & password have been entered?

Code:

sub login(){
my $user = CGI: aram('UserName');
my $password = CGI: aram('Password');
my $rows = 0;

$RstFindUser = $dbh->prepare("SELECT Username, Password FROM user WHERE Username = '$user'");
$RstFindUser->execute;
$rows = $RstFindUser->rows;
my ($uname, $pword) = $RstFindUser->fetchrow;
$RstFindUser->finish;
if($rows){
if($password=~$pword){
showForm($user,$password);
}
else {
print CGI::header();
print qq{
<HTML>
<HEAD>
<TITLE>E-Commerce Login</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<H2>The Password you entered is invalid for User: $user<BR><a href="contest_input">Pick a different Username or Try Again!</
a>
</BODY>
</HTML>};
}
} else {
showForm($user,$password);
}
} # login


-Loki

Reply With Quote
  #2  
Old August 18th, 2000, 04:05 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
my ($user) = $q->param('UserName');
my ($password) = $q->param('Password');
unless ($user and $password) {
&error;
last;
}

sub error {
print "Content-type: text/htmlnn";
print "Missing field(s)n";
}

Reply With Quote
  #3  
Old August 18th, 2000, 04:40 PM
Loki Loki is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Norman, OK, USA
Posts: 12 Loki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Loki
Oops.. I should have posted earlier, but got tied up with something. Thanks for the replay freebsd. Actually, here's what I ended up doing, and it worked!

code:
sub login(){
my $user = CGI: aram('UserName') | | undef;
my $password = CGI: aram('Password') | | undef;
my $rows = 0;

my $error = "";
$error .= &checkvalid($user,'UserName',B);
$error .= &checkvalid($password,'Password',B);

if ($error) {
$form .= "<H3 ALIGN="CENTER">Error</H3><CENTER><FONT SIZE="4">You have some invalid or missing information.</FONT>n";
$form .= "<BR> $error</center>n";
$TEMPLATE = $TEMPLATE_DIR . "/" . $plaintmpl;
print CGI::header();

open TEMPLATE;

while(<TEMPLATE> ) {
$_ =~ s/<%CONTESTFORM%>/$form/g;
print $_;
}
} else {

$RstFindUser = $dbh->prepare("SELECT Username, Password FROM user WHERE Username = '$user'");
$RstFindUser->execute;
$rows = $RstFindUser->rows;
my ($uname, $pword) = $RstFindUser->fetchrow;
$RstFindUser->finish;

if($rows){
if($password=~$pword){
showForm($user,$password);
}
else {
print CGI::header();
print qq{
<HTML>
<HEAD>
<TITLE>Total Football Login</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<H2>The Password you entered is invalid for User: $user<BR><a href="total_football">Pick a different Username or Try Again!</a>
</BODY>
</HTML>};
}

} else {
showForm($user,$password);
}
}
} # login


---------------------------------

Yeah, seems to be ALOT more code than your fix. hehe.. but it works.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > confirming username & password


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway