473,473 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to confirm uname and pswd and allow access to next page.

9 New Member
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.
Jul 19 '07 #1
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
Jul 19 '07 #2
KevinADC
4,059 Recognized Expert Specialist
A far more gentle introduction to CGI programming with perl can be found here:

http://www.cgi101.com/book/

Or a more indepth intro to CGI in general and CGI.pm in specifc can be found here (chapter 12):

http://www.perl.org/books/beginning-perl/
Jul 19 '07 #3
gemstone
9 New Member
hi jeff,
this is what i've done so far. pls check if its correct.
thanks.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. # Login CGI
  3.  
  4. use CGI ':standard';
  5.  
  6. use warnings;
  7. use strict;
  8.  
  9. print "Content-type: text/html\n\n";
  10. print "<html>\n";
  11. print "<body>\n";
  12. print "<b><center><font size=7 color="#6699FF" face=arial>DELTAZIA</font></center></b>\n";
  13. print "<br><hr WIDTH="100%" COLOR="#6699FF" SIZE="6">
  14. <br><div style ="border:2px solid #CCCDDD; width:250px; height:220px; background-color:#99DDFF;">\n";
  15. print "<br><b><p align="center">LOGIN</p></b>\n";
  16.  
  17. print "<p align="center">Username <input type=text size=20><br></p>
  18. <p align="center">Password <input type=password name=password size=20><br></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  19. <input type=submit value=Login>&nbsp;&nbsp;
  20. <input type=reset value=Reset><br></p>
  21. </div>\n";
  22. print "</body>\n";
  23. print "</html>\n";
  24.  
  25. $uname=param('Username');
  26. $pswd=param('Password');
  27. if ($uname eq '') {
  28. print"<h3><b>Kindly enter both username and passwork to proceed forward</b></h3>\n";
  29. sendfile("login1.html");
  30. }
  31.  
  32. open (INF,"c:/minu/unpw.txt") or die "could not open the file: $!";
  33. while (<INF>) {
  34. ($un,$pw)=split(/:/);
  35. for ($_[0])
  36. if($uname eq $un) {
  37. if(($uname eq $un) && ($pswd eq $pw)) {
  38. sendfile("page22.html");
  39. } else {
  40. print "<h3><font color="red" face="arial">Invalid username or password</font></h3>\n";
  41. }
  42. } else {
  43. $_++;
  44. } else {
  45. print "<h3><font color="red" face="arial">Username or password does not exist</font></h3>\n";
  46. sendfile("login1.html");
  47. }
  48. }
  49.  
  50. close(INF);
  51.  
Jul 20 '07 #4
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:

Expand|Select|Wrap|Line Numbers
  1. my $flag = 0;
  2. open (INF,"c:/minu/unpw.txt") or die "could not open the file: $!";
  3. while(<INF>){
  4.    chomp;
  5.    my ($un,$pw)= split(/:/);
  6.    if ($uname eq $un && $pswd eq $pw){
  7.       $flag = 1;
  8.       last;
  9.    }
  10. }
  11. if ($flag) {
  12.    #login success
  13. }
  14. else {
  15.    #login failed
  16. }
  17.  
Jul 20 '07 #5
gemstone
9 New Member
hi,
thanks for checking it. i wanna know what does flag do in it. im new tp perl so i wanna know.
Jul 20 '07 #6
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:

Expand|Select|Wrap|Line Numbers
  1. if ($flag)
but you can write it like this if you prefer:

Expand|Select|Wrap|Line Numbers
  1. if ($flag == 1)
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.
Jul 20 '07 #7
gemstone
9 New Member
oh ok. so is this correct now?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  2. use strict;
  3. use warnings;
  4. use CGI;
  5. # LOGIN CGI;
  6. # use CGI ':standard';
  7.  
  8. print "Content-type: text/html\n\n";
  9. print "<html>\n";
  10. print "<form action=".../trial1july18.plx" method="post">
  11. print "<body>\n";
  12. print "<b><center><font size=7 color="#6699FF" face=arial>DELTAZIA</font></center></b>\n";
  13. print "<br><hr WIDTH="100%" COLOR="#6699FF" SIZE="6">
  14. <br><div style ="border:2px solid #CCCDDD; width:250px; height:220px; background-color:#99DDFF;">\n";
  15. print "<br><b><p align="center">LOGIN</p></b>\n";
  16.  
  17. print "<p align="center">Username <input type=text size=20><br></p>
  18. <p align="center">Password <input type=password name=password size=20><br></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  19. <input type=submit value=Login>&nbsp;&nbsp;
  20. <input type=reset value=Reset><br></p></div>\n";
  21. print "</form>";
  22. print "</body>\n";
  23. print "</html>\n";
  24. $uname=param('Username');
  25. $pswd=param('Password');
  26.  
  27. if ($uname eq '') {
  28. print"<h3><b>Kindly enter both username and passwork to proceed forward</b></h3>\n";
  29. sendfile("login1.html");
  30. }
  31.  
  32. my $flag=0;
  33. open (INF,"c:/minu/unpw.txt") or die "could not open the file: $!";
  34. while (<INF>) {
  35. chomp;
  36. my ($un,$pw)=split(/:/);
  37. if($uname eq $un && $pswd eq $pw) {
  38. $flag=1;
  39. last;
  40. }
  41. }
  42. if ($flag) {
  43. sendfile("page22.html");
  44. } else {
  45. print "<h3><font color="red" face="arial">Invalid username or password</font></h3>\n";
  46. sendfile("login1.html");
  47. }
  48.  
  49. close(INF);
  50.  
Jul 20 '07 #8
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.
Jul 20 '07 #9
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
Jul 20 '07 #10
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.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  2. use strict;
  3. use warnings;
  4. use CGI;
  5. # LOGIN CGI;
  6. # use CGI ':standard';
  7.  
  8. print <<"END_HTML";
  9. Content-type: text/html
  10.  
  11. <html>
  12. <form action=".../trial1july18.plx" method="post">
  13. <body>
  14. <b><center><font size=7 color="#6699FF" face=arial>DELTAZIA</font></center></b>
  15. <br><hr WIDTH="100%" COLOR="#6699FF" SIZE="6">
  16. <br><div style ="border:2px solid #CCCDDD; width:250px; height:220px; background-color:#99DDFF;">
  17. <br><b><p align="center">LOGIN</p></b>
  18. <p align="center">Username <input type=text size=20><br></p>
  19. <p align="center">Password <input type=password name=password size=20><br></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  20. <input type=submit value=Login>&nbsp;&nbsp;
  21. <input type=reset value=Reset><br></p></div>
  22. </form>
  23. </body>
  24. </html>
  25. END_HTML
  26.  
  27. my $uname = param('Username');
  28. my $pswd = param('Password');
  29.  
  30. if ($uname eq '') {
  31.     print qq{<h3><b>Kindly enter both username and passwork to proceed forward</b></h3>\n};
  32.     sendfile("login1.html");
  33. }
  34.  
  35. my $flag = 0;
  36. open(INF, "c:/minu/unpw.txt") or die "could not open the file: $!";
  37. while (<INF>) {
  38.     chomp;
  39.     my ($un, $pw) = split ':';
  40.     if ($uname eq $un && $pswd eq $pw) {
  41.         $flag=1;
  42.         last;
  43.     }
  44. }
  45. close(INF);
  46.  
  47. if ($flag) {
  48.     sendfile("page22.html");
  49. } else {
  50.     print qq{<h3><font color="red" face="arial">Invalid username or password</font></h3>\n};
  51.     sendfile("login1.html");
  52. }
  53.  
  54. close(INF);
  55.  
- Miller
Jul 20 '07 #11
gemstone
9 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  2. use strict;
  3. use warnings;
  4. use CGI;
  5. # LOGIN CGI;
  6. # use CGI ':standard';
  7.  
  8. print <<"END_HTML";
  9. Content-type: text/html
  10.  
  11. <html>
  12. <form action=".../trial1july18.plx" method="post">
  13. <body>
  14. <b><center><font size=7 color="#6699FF" face=arial>DELTAZIA</font></center></b>
  15. <br><hr WIDTH="100%" COLOR="#6699FF" SIZE="6">
  16. <br><div style ="border:2px solid #CCCDDD; width:250px; height:220px; background-color:#99DDFF;">
  17. <br><b><p align="center">LOGIN</p></b>
  18. <p align="center">Username <input type=text size=20><br></p>
  19. <p align="center">Password <input type=password name=password size=20><br></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  20. <input type=submit value=Login>&nbsp;&nbsp;
  21. <input type=reset value=Reset><br></p></div>
  22. </form>
  23. </body>
  24. </html>
  25. END_HTML
  26.  
  27. my $uname = param('Username');
  28. my $pswd = param('Password');
  29.  
  30. if ($uname eq '') {
  31.     print qq{<h3><b>Kindly enter both username and passwork to proceed forward</b></h3>\n};
  32.     sendfile("login1.html");
  33. }
  34.  
  35. my $flag = 0;
  36. open(INF, "c:/minu/unpw.txt") or die "could not open the file: $!";
  37. while (<INF>) {
  38.     chomp;
  39.     my ($un, $pw) = split ':';
  40.     if ($uname eq $un && $pswd eq $pw) {
  41.         $flag=1;
  42.         last;
  43.     }
  44. }
  45. close(INF);
  46.  
  47. if ($flag) {
  48.     sendfile("page22.html");
  49. } else {
  50.     print qq{<h3><font color="red" face="arial">Invalid username or password</font></h3>\n};
  51.     sendfile("login1.html");
  52. }
  53.  
  54. close(INF);
  55.  
- Miller
Jul 20 '07 #12
KevinADC
4,059 Recognized Expert Specialist
hehehe.... are you speechless gemstone? ;)
Jul 20 '07 #13
gemstone
9 New Member
not speechless exactly but im trying to polish what i've done so far. got lots more to do.

hehehe.... are you speechless gemstone? ;)
Jul 21 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
13
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...
1
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,...
5
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...
1
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...
5
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?...
4
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...
2
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...
5
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> ...
0
marktang
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,...
0
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...
0
Oralloy
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,...
1
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...
0
tracyyun
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...
1
isladogs
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.