Login page perl/CGI

Discussion in 'Perl Misc' started by sandy, Apr 27, 2007.

  1. sandy

    sandy Guest

    hello,,,,,,,,,
    i am creating login page using Perl/CGI facing prob... able to
    connect DB but from there facing prob
    If u have related code of login page in Perl please send me on


    please help me


    i am using MySQL as DB user name:root password:root database name:ITS

    and Table is User_login,
    Column 1: User_Name
    Column 2: User_Pass

    --
    #!c:/perl/bin/perl.exe
    use CGI qw:)standard);
    use CGI::Carp qw(warning's fatalsToBrowser);
    use strict;
    use DBI;


    print "Content-type: text/html\n\n";
    print <<BodyHTML;
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
    <html lang="en" xml:lang="en" xmlns=" http://www.w3.org/1999/xhtml">
    <head>
    <title>Registration Form</title>
    </head>

    <body>
    <form name = "login" action = "logincheck.cgi " method = "POST">
    <table>
    <tr>
    <td>
    User Name<br />(25 characters or less)
    </td>
    <td>
    Password<br />(8 - 15 alphanumeric characters)
    </td>
    </tr>
    <tr>
    <td><input type = "text" name = "UserName" id = "UserName" size = "25"
    maxlength = "25" tabindex = "0" />
    </td>
    <td><input type = "text" name = "Password" id = "Password" size = "15"
    maxlength = "15" tabindex = "1" />
    </tr>
    <tr>
    <td>
    <input type = "submit" value = "Login" tabindex = "2" />
    </td>
    </tr>
    <tr>
    <td>
    <p>To register go to the <a href = "register.cgi">registration</a>
    page.</p>
    </td>
    </tr>
    </table>
    </form>
    BodyHTML
    print end_html;

    my $dbh = DBI->connect("DBI:mysql:database:localhost","its","root",
    { RaiseError => 1,
    AutoCommit => 1 }) or &dienice("Can't connect to database:
    $DBI::errstr");

    my $UserName=param('UserName');
    my $Password=param('Password');
    my $sth = $dbh->prepare("select * from User_Login where User_Name
    = ?") or &dbdie;
    $sth->execute($UserName) or &dbdie;
    if (my $name = $sth->fetchrow_hashref)
    {
    my $sth = $dbh->prepare("select * from user_Login where root = ?") or
    &dbdie;
    $sth->execute($Password) or &dbdie;
    if (my $pass = $sth->fetchrow_hashref)
    {
    print redirect(- location=>"index.cgi");
    }
    else { &dienice(qq(The password is invalid. Go to the <a href =
    "passreset.cgi">password reset</a> page to reset your password.)); }
    }
    else { &dienice(qq(Username does not exist. Go to the <a href = "
    custreg.cgi">registration</a> page to register.)); }
    $dbh->disconnect;
    print end_html;

    sub dienice {
    my ($msg) = @_;
    print "<h1>$msg</h1>";
    exit;
    }

    sub dbdie {
    my ($errmsg) = "$DBI::errstr<br />";
    &dienice($errmsg);
    }
    Sandip B Bhosale.
     
    sandy, Apr 27, 2007
    #1
    1. Advertising

  2. On Apr 27, 6:47 am, sandy <> multiposts

    Please don't.
     
    Brian McCauley, Apr 27, 2007
    #2
    1. Advertising

  3. sandy

    J. Gleixner Guest

    sandy wrote:
    > hello,,,,,,,,,
    > i am creating login page using Perl/CGI facing prob... able to
    > connect DB but from there facing prob


    Try facing North instead of prob.
    [...]
    > please help me


    Create a program that works from the command line, no HTML. Once
    that works, then add in the HTML.

    > i am using MySQL as DB user name:root password:xxxx database name:ITS

    ahhhh.. the values for your username and password and database aren't
    important..

    > and Table is User_login,
    > Column 1: User_Name
    > Column 2: User_Pass
    >
    > --
    > #!c:/perl/bin/perl.exe
    > use CGI qw:)standard);
    > use CGI::Carp qw(warning's fatalsToBrowser);
    > use strict;
    > use DBI;
    >
    >
    > print "Content-type: text/html\n\n";

    [...]

    sooo.. you're using the CGI module but you aren't using any of CGI's
    modules to help you with your HTML???.. If all you want is the
    param method, then you don't need :standard. If you're going to
    include all of the 'standard' methods, then use them.


    > my $dbh = DBI->connect("DBI:mysql:database:localhost","its","root",
    > { RaiseError => 1,
    > AutoCommit => 1 }) or &dienice("Can't connect to database:
    > $DBI::errstr");


    Read up on what 'RaiseError' does. 'dienice' for a subroutine that
    doesn't actually call die, isn't nice.

    No need for '&'.

    > my $UserName=param('UserName');
    > my $Password=param('Password');
    > my $sth = $dbh->prepare("select * from User_Login where User_Name
    > = ?") or &dbdie;


    Hopefully you're not storing your customer's passwords in clear text.
    Encrypt them, somehow.

    > $sth->execute($UserName) or &dbdie;
    > if (my $name = $sth->fetchrow_hashref)
    > {
    > my $sth = $dbh->prepare("select * from user_Login where root = ?") or
    > &dbdie;


    'where root = ?' ????

    You have a column named 'root'?

    Maybe...

    if( param('UserName') and param('Password') )
    {
    my $sql = 'select 1 from user_login where user_name=? and user_pass=?';
    my $sth = $dbh->prepare( $sql );
    $sth->execute( param('UserName'), param('Password') );
    etc..
    }
    else
    {
    #print some message here..
    }

    > $sth->execute($Password) or &dbdie;
    > if (my $pass = $sth->fetchrow_hashref)
    > {
    > print redirect(- location=>"index.cgi");
    > }
    > else { &dienice(qq(The password is invalid. Go to the <a href =
    > "passreset.cgi">password reset</a> page to reset your password.)); }
    > }
    > else { &dienice(qq(Username does not exist. Go to the <a href = "
    > custreg.cgi">registration</a> page to register.)); }


    If your site has any personal information on it, about the customer,
    then don't provide the reason why it failed. Just state that the
    username or password is not found, in one message.
     
    J. Gleixner, Apr 27, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,356
    Jürgen Exner
    Jul 31, 2003
  2. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    605
    Michael Sparks
    Jul 30, 2005
  3. sandy

    Login page perl/CGI

    sandy, Apr 27, 2007, in forum: HTML
    Replies:
    1
    Views:
    2,141
    Michael
    Apr 27, 2007
  4. Shannon

    login page stays on login page

    Shannon, Jan 9, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    547
    Shannon
    Jan 9, 2008
  5. kath
    Replies:
    4
    Views:
    625
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page