Verifying a username and a password : Form « CGI « Perl

Perl
1. Array
2. CGI
3. Class
4. Data Type
5. Database
6. File
7. GUI
8. Hash
9. Language Basics
10. Network
11. Regular Expression
12. Report
13. Statement
14. String
15. Subroutine
16. System Functions
17. Win32
18. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Perl » CGI » Form 
Verifying a username and a password
 

<HTML>
<HEAD>
<TITLE>Verifying a username and a password.</TITLE>
</HEAD>
<BODY>
      Type in your username and password below.
   <FORM ACTION = "index.pl" METHOD = "POST">
   Username:<INPUT SIZE = "40" NAME = "USERNAME">
   Password:<INPUT SIZE = "40" NAME = "PASSWORD" TYPE = PASSWORD>
   <INPUT TYPE = "SUBMIT" VALUE = "Enter">
   </FORM>
</BODY>
</HTML>

#!perl
use CGI qw(:standard);

$testUsername = param"USERNAME" );
$testPassword = param"PASSWORD" );

open FILE, "password.txt" || die "The database could not be opened";

while $line = <FILE> )
{
   chomp $line;
   $username, $password = split",", $line );
   
   if $testUsername eq $username )
   {
      $userVerified = 1;
      if $testPassword eq $password )
      {
         $passwordVerified = 1;
         last;
      }
   
}

closeFILE );
print header;

if $userVerified && $passwordVerified )
{
   accessGranted();
}
elsif $userVerified && !$passwordVerified )
{
   wrongPassword();
}
else
{
   accessDenied();
}

sub accessGranted
{
   print "<TITLE>Thank You</TITLE>";
   print "Permission has been granted, $username.";
   print "<BR>Enjoy the site.";
}

sub wrongPassword
{
   print "<TITLE>Access Denied</TITLE>";
   print "You entered an invalid password.<BR>";
   print "Access has been denied.";
}

sub accessDenied
{
   print "<TITLE>Access Denied</TITLE>";
   print "You were denied access to this server.";
}

#File: password.txt

#account1,password1
#account2,password2
#account3,password3

   
  
Related examples in the same category
1. Form Input Types
2. Demonstrates GET method with HTML form.
3. Demostrates POST method with HTML form.
4. Demonstrates use of CGI.pm with HTML form.
5. Create HTML form with CGI
6. Get form submitted value
7. Using param() function to get parameter
8. Using CGI function to check the parameter
9. Create a form and set the method and action
10. Create a form with submit button
11. Process form with regular expression: first name and last name
12. Process form with regular expression: date
13. Process form with regular expression: time
14. Generate the HTML form
15. Printing the Name Input Using the CGI Module
16. Get form value with param
17. Generate and Process Forms
18. Form Mail
19. Form based table editing
20. Create a form with Perl code
21. Code to Accept Input with the CGI Module
22. Capitalize the first letter of each parameter using ucfirst
23. A Form-Based Example
24. Learn about the current CGI request
25. Read the data for a CGI GET request
26. Read the data passed to a script on the command line?
27. Decoding the Input Data
28. The POST Method
29. Sample Database Query
30. Writing a cookie to the client computer
31. Add a New Phone Number
32. Sessions - Preserving State
33. Separate the form and perl script
34. Add form data to database
35. Passing parameter to perl CGI code
36. EMail sending form
37. Guest book form
38. Data-Entry Forms in Web Pages
39. Using LI
40. Using the option select box
41. Reading text in textarea
42. Querying all the parameters
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.