Samy_rio has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, previously i had problem in Password, now it is rectified.

How to display an alert message? if user entered Password is wrong.

I tried the below coding for wrong password detection.

if ($valid_user eq '') { print redirect('http://localhost/index.html'); }

It works fine, but i need an alert message in the same home page, where user enters the user name and password.

Regards,
Velusamy R

Replies are listed 'Best First'.
Re: Error Message
by bradcathey (Prior) on Jul 04, 2005 at 11:35 UTC

    I think you mean "dialog" box. Obviously you are using CGI.pm so I would just create a form on index.html that contains at least 2 inputs, one for name and one for password, with a submit button that sends everything to your script for another round of validation.

    The question I have is how users are getting to the code you show? Wouldn't that be from a form? How/where are you getting $valid_user in the first place? How about seeing more of what you have written?


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

      Here I placed the "ind.cgi" coding and my home page "index.html" calling this cgi when user click the submit button.

      #!C:\perl\bin\perl use strict; use CGI qw/:standard/; use DBI; my $q = new CGI; my $dbh = DBI->connect("DBI:mysql:project", {PrintError =>0, RaiseErro +r =>0}) ; my $us=$q->param('user'); my $pas=$q->param('pass'); my $sth = $dbh->prepare("SELECT * FROM user WHERE uname=? AND pass=PAS +SWORD(?)"); $sth->execute($us,$pas); my ($valid_user, $pp) = $sth->fetchrow_array(); if ($valid_user eq '') { print redirect('http://localhost/index.html'); } print $q->header("text/html"), $q->start_html(-title=>uc($q->param('REG')), -Background=>'EiffelTower +.tif'); print "<br><br><H1 align='center'><b><font face='Euclid fraktur' color +='cyan'>P</font><font face='Euclid fraktur' color='megantha'>E</font> +<font face='Euclid fraktur' color='yellow'>R</font><font face='Euclid + fraktur' color='pink'>L</font> <font face='Euclid fraktur' color='Re +d'>M</font><font face='Euclid fraktur' color='Green'>O</font><font fa +ce='Euclid fraktur' color='blue'>D</font><font face='Euclid fraktur' +color='cyan'>U</font><font face='Euclid fraktur' color='megantha'>L</ +font><font face='Euclid fraktur' color='yellow'>E</font><font face='E +uclid fraktur' color='orange'>S</font></H1>"; $dbh->disconnect; print $q->end_html;
        couldn't resist rewriting that huge print statement :)
        my @colors = qw/ cyan megantha yellow pink Red Green blue cyan meganth +a yellow orange /; my $font = 'Euclid fraktur'; print "<br><br><H1 align='center'><b>"; foreach my $letter ( split //, 'PERL MODULES' ){ do { print $letter; next; } if $letter = ' '; # special case of s +pace printf "<font face='%s' color='%s'>%s</font>", $font, $colors[0], $l +etter; push @colors, shift @colors; # rotate the colors } print "</b></H1>";

        As for your primary issue, I would suggest that index.cgi contain the login form (instead of a static index.html) so that you can dynamically add a message to it. Some pseudo code:
        $message = ''; if( $login_form_submitted ){ check user and pass params if ok redirect to main page else $message = 'login failed' end } print login form here, including $message if it is set