hi guys,
I have to accept the username and password entered on the web page(designed using html) store them in 2 variables (say, $var1 and $var2) and compare it with a text file(unpw.txt) which already has the list of username and its password (which will be split and stored as $uname and $pswd).
i was told to use html in perl scripts. im having trouble with perl and also in including html in it.
pls help.
13 1598 numberwhun 3,509
Recognized Expert Moderator Specialist
I haven't played with it as of yet, but when you are doing coding of web sites with Perl, you are delving into the realms of CGI. For an excellent intro tutorial on how CGI can be used, see this one located here at thescripts.com.
That should show you how perl can interact with HTML, but you will definitely either need someone more fluent in CGI or to find a good tutorial on it.
That said though, you may want to post the code that you have tried thus far as others will ask to see it as well. We are all very glad to assist, but you have to show what you have tried already.
Regards,
Jeff
hi jeff,
this is what i've done so far. pls check if its correct.
thanks. -
#!/usr/bin/perl
-
# Login CGI
-
-
use CGI ':standard';
-
-
use warnings;
-
use strict;
-
-
print "Content-type: text/html\n\n";
-
print "<html>\n";
-
print "<body>\n";
-
print "<b><center><font size=7 color="#6699FF" face=arial>DELTAZIA</font></center></b>\n";
-
print "<br><hr WIDTH="100%" COLOR="#6699FF" SIZE="6">
-
<br><div style ="border:2px solid #CCCDDD; width:250px; height:220px; background-color:#99DDFF;">\n";
-
print "<br><b><p align="center">LOGIN</p></b>\n";
-
-
print "<p align="center">Username <input type=text size=20><br></p>
-
<p align="center">Password <input type=password name=password size=20><br></p><p>
-
<input type=submit value=Login>
-
<input type=reset value=Reset><br></p>
-
</div>\n";
-
print "</body>\n";
-
print "</html>\n";
-
-
$uname=param('Username');
-
$pswd=param('Password');
-
if ($uname eq '') {
-
print"<h3><b>Kindly enter both username and passwork to proceed forward</b></h3>\n";
-
sendfile("login1.html");
-
}
-
-
open (INF,"c:/minu/unpw.txt") or die "could not open the file: $!";
-
while (<INF>) {
-
($un,$pw)=split(/:/);
-
for ($_[0])
-
if($uname eq $un) {
-
if(($uname eq $un) && ($pswd eq $pw)) {
-
sendfile("page22.html");
-
} else {
-
print "<h3><font color="red" face="arial">Invalid username or password</font></h3>\n";
-
}
-
} else {
-
$_++;
-
} else {
-
print "<h3><font color="red" face="arial">Username or password does not exist</font></h3>\n";
-
sendfile("login1.html");
-
}
-
}
-
-
close(INF);
-
KevinADC 4,059
Recognized Expert Specialist
Its sort of correct. Ignoring all your syntax errors, you would write the routine that checks the name and password like so: - my $flag = 0;
-
open (INF,"c:/minu/unpw.txt") or die "could not open the file: $!";
-
while(<INF>){
-
chomp;
-
my ($un,$pw)= split(/:/);
-
if ($uname eq $un && $pswd eq $pw){
-
$flag = 1;
-
last;
-
}
-
}
-
if ($flag) {
-
#login success
-
}
-
else {
-
#login failed
-
}
-
hi,
thanks for checking it. i wanna know what does flag do in it. im new tp perl so i wanna know.
KevinADC 4,059
Recognized Expert Specialist
$flag is just used to determine if the login was a success or failure after the "while" loop finishes checking the user input against the file. $flag is initially given a value of 0 (zero) which in perl is considered a false value. During the "while" loop, if the name and password both match, $flag is changed to 1 (one) which is now a true value. "last" ends the "while" loop at the point. The if/else condition that follows checks the value of $flag. We do not need to check the actual value of $flag, we only need to check that it is a true (defined) value:
but you can write it like this if you prefer:
using "flags" is common practice in programming. They are sometimes called binary flags because they can have only two values:
1 (on/true)
0 (off/false)
that is not the only way you could something like this, but it's fairly common and It is most likely the way I would do it myself.
oh ok. so is this correct now? -
#!/usr/bin/perl -T
-
use strict;
-
use warnings;
-
use CGI;
-
# LOGIN CGI;
-
# use CGI ':standard';
-
-
print "Content-type: text/html\n\n";
-
print "<html>\n";
-
print "<form action=".../trial1july18.plx" method="post">
-
print "<body>\n";
-
print "<b><center><font size=7 color="#6699FF" face=arial>DELTAZIA</font></center></b>\n";
-
print "<br><hr WIDTH="100%" COLOR="#6699FF" SIZE="6">
-
<br><div style ="border:2px solid #CCCDDD; width:250px; height:220px; background-color:#99DDFF;">\n";
-
print "<br><b><p align="center">LOGIN</p></b>\n";
-
-
print "<p align="center">Username <input type=text size=20><br></p>
-
<p align="center">Password <input type=password name=password size=20><br></p><p>
-
<input type=submit value=Login>
-
<input type=reset value=Reset><br></p></div>\n";
-
print "</form>";
-
print "</body>\n";
-
print "</html>\n";
-
$uname=param('Username');
-
$pswd=param('Password');
-
-
if ($uname eq '') {
-
print"<h3><b>Kindly enter both username and passwork to proceed forward</b></h3>\n";
-
sendfile("login1.html");
-
}
-
-
my $flag=0;
-
open (INF,"c:/minu/unpw.txt") or die "could not open the file: $!";
-
while (<INF>) {
-
chomp;
-
my ($un,$pw)=split(/:/);
-
if($uname eq $un && $pswd eq $pw) {
-
$flag=1;
-
last;
-
}
-
}
-
if ($flag) {
-
sendfile("page22.html");
-
} else {
-
print "<h3><font color="red" face="arial">Invalid username or password</font></h3>\n";
-
sendfile("login1.html");
-
}
-
-
close(INF);
-
KevinADC 4,059
Recognized Expert Specialist
It's getting there but the code overall will not work. You have not declared your variables with "my", and the overall logicl could be better.
I think we would all appreciate if you start using the code tags to post formatted code.
miller 1,089
Recognized Expert Top Contributor
Please enclose your posted code in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use [code] tags in future.
- MODERATOR
miller 1,089
Recognized Expert Top Contributor
Also, it would do you good to start ensuring that you code at least doesn't contain syntax errors before asking questions. Here is your code with the syntax errors fixed. The logic and overall design still needs to be fixed. -
#!/usr/bin/perl -T
-
use strict;
-
use warnings;
-
use CGI;
-
# LOGIN CGI;
-
# use CGI ':standard';
-
-
print <<"END_HTML";
-
Content-type: text/html
-
-
<html>
-
<form action=".../trial1july18.plx" method="post">
-
<body>
-
<b><center><font size=7 color="#6699FF" face=arial>DELTAZIA</font></center></b>
-
<br><hr WIDTH="100%" COLOR="#6699FF" SIZE="6">
-
<br><div style ="border:2px solid #CCCDDD; width:250px; height:220px; background-color:#99DDFF;">
-
<br><b><p align="center">LOGIN</p></b>
-
<p align="center">Username <input type=text size=20><br></p>
-
<p align="center">Password <input type=password name=password size=20><br></p><p>
-
<input type=submit value=Login>
-
<input type=reset value=Reset><br></p></div>
-
</form>
-
</body>
-
</html>
-
END_HTML
-
-
my $uname = param('Username');
-
my $pswd = param('Password');
-
-
if ($uname eq '') {
-
print qq{<h3><b>Kindly enter both username and passwork to proceed forward</b></h3>\n};
-
sendfile("login1.html");
-
}
-
-
my $flag = 0;
-
open(INF, "c:/minu/unpw.txt") or die "could not open the file: $!";
-
while (<INF>) {
-
chomp;
-
my ($un, $pw) = split ':';
-
if ($uname eq $un && $pswd eq $pw) {
-
$flag=1;
-
last;
-
}
-
}
-
close(INF);
-
-
if ($flag) {
-
sendfile("page22.html");
-
} else {
-
print qq{<h3><font color="red" face="arial">Invalid username or password</font></h3>\n};
-
sendfile("login1.html");
-
}
-
-
close(INF);
-
- Miller
you have used close (INF); twiceis that possible?
Also, it would do you good to start ensuring that you code at least doesn't contain syntax errors before asking questions. Here is your code with the syntax errors fixed. The logic and overall design still needs to be fixed. -
#!/usr/bin/perl -T
-
use strict;
-
use warnings;
-
use CGI;
-
# LOGIN CGI;
-
# use CGI ':standard';
-
-
print <<"END_HTML";
-
Content-type: text/html
-
-
<html>
-
<form action=".../trial1july18.plx" method="post">
-
<body>
-
<b><center><font size=7 color="#6699FF" face=arial>DELTAZIA</font></center></b>
-
<br><hr WIDTH="100%" COLOR="#6699FF" SIZE="6">
-
<br><div style ="border:2px solid #CCCDDD; width:250px; height:220px; background-color:#99DDFF;">
-
<br><b><p align="center">LOGIN</p></b>
-
<p align="center">Username <input type=text size=20><br></p>
-
<p align="center">Password <input type=password name=password size=20><br></p><p>
-
<input type=submit value=Login>
-
<input type=reset value=Reset><br></p></div>
-
</form>
-
</body>
-
</html>
-
END_HTML
-
-
my $uname = param('Username');
-
my $pswd = param('Password');
-
-
if ($uname eq '') {
-
print qq{<h3><b>Kindly enter both username and passwork to proceed forward</b></h3>\n};
-
sendfile("login1.html");
-
}
-
-
my $flag = 0;
-
open(INF, "c:/minu/unpw.txt") or die "could not open the file: $!";
-
while (<INF>) {
-
chomp;
-
my ($un, $pw) = split ':';
-
if ($uname eq $un && $pswd eq $pw) {
-
$flag=1;
-
last;
-
}
-
}
-
close(INF);
-
-
if ($flag) {
-
sendfile("page22.html");
-
} else {
-
print qq{<h3><font color="red" face="arial">Invalid username or password</font></h3>\n};
-
sendfile("login1.html");
-
}
-
-
close(INF);
-
- Miller
KevinADC 4,059
Recognized Expert Specialist
hehehe.... are you speechless gemstone? ;)
not speechless exactly but im trying to polish what i've done so far. got lots more to do.
hehehe.... are you speechless gemstone? ;)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Geoff May |
last post by:
I'm busy rewriting by F1 database and I want to use cookies to store
various user definable views, (basically so that when the visitor
returns to a specific page, that page will redisplay in the...
|
by: Chris |
last post by:
I can create Javascript confirm message boxes during page creation, etc
adding them to the button attributes (many good posts on this!). But how can
I add this event after the button is pressed?
I...
|
by: freshRecruit |
last post by:
Hi,
I am having a problem, and is driving me nuts and my deadline is fast
approaching. Please do help me..
This is a webapplication with a usercontrol which has some buttons for
adding,...
|
by: rodchar |
last post by:
hey all,
in my page load i'm attaching a javascript confirm message to my save
button. my problem is i have some client side validation which uses a Custom
Validator web control and when i make...
|
by: manika02 |
last post by:
Hi,
I want to add a JavaScript confirmation box on a DropDown. I want to display
the confirmation box only when a particular value is selected. I check this
condition in selectedindexchanged event...
| |
by: balakrishnan.dinesh |
last post by:
hi Frnds,
I need Confirm box with "yes" or "no" buttons, Is that
possible in JAVASCRIPT ,
Can anyone tell me the solution for this or anyother way to create
confirm box with "yes" or "no" button?...
|
by: mamun |
last post by:
Hi All,
I have the following situation and am looking for answer in C#.
I have a datagrid and putting checkbox next to each record. In the
header I have a Delete button.
I want users to...
|
by: thirunavukarasukm |
last post by:
Hai....
"i want used confirm in javascript in code behind"
i am used confirm button ,,,in code behind.
if the confirm button worked
the function is return the true...
|
by: ahilar12 |
last post by:
hi all,
i wanted to check whether the password entered matches with the confirm password.either through javascript or through php.i have enclosed my code somebody help on this
<html>
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |