繁体   English   中英

为什么此密码检查无法按预期工作?

[英]Why is this password check not working as expected?

我试图从PHP扩展。 这是我遇到的一个基本问题,无法弄明白......

password.pl

#!/usr/bin/perl

use CGI;
$q = new CGI;

print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Card</title>';
print '</head>';
print '<body>';
print '<FORM METHOD=POST ACTION=/card.pl>';
print '<INPUT TYPE=password NAME=password SIZE=25>';
print '<input type=submit value=Submit>';
print '</FORM>';
print '</body>';
print '</html>';

1;

card.pl

#!/usr/bin/perl

use CGI;
$q = new CGI;

$password = $q->param("password");
print $password;
if ($password == pass)
{
  print 'Yup';
}
else
{
  print 'Wrong Password';
}


1;

什么都没有从password.pl表单传递给card.pl? 我以前用过一个类似的例子没问题?

更多咖啡......

use strict; use warnings; 并查看您的错误日志。 还要验证您的HTML。

然后,您将收到以下问题的警报:

在card.pl第7行使用“strict subs”时,不允许使用Bareword“pass”。

你可能想要:

($password eq 'pass')

在我继续寻求废除CGI.pm的滥用时,你的第一个脚本会更好 -

use strict;
use warnings;
use CGI qw( :standard );

print
    header(),
    start_html("O HAI CARD"),
    start_form(-action => "card.pl"),
    fieldset(
             legend("None Shall Pass!"),
             password_field(-name => "password",
                            -size => 25),
             submit(-value => "Submit"),
             ),
    end_form(),
    end_html();

或许,你的第二个,例如,等等 -

use strict;
use warnings;
use CGI;
my $q = CGI->new;

print
    $q->header,
    $q->start_html("O HAI CARD");

my $password = $q->param("password");

if ( $password eq "pass" )
{
  print $q->h2("You're all good");
}
else
{
  print $q->h2({-style => "color:#a00"},
           "You're all good");
}

print $q->end_html();

或者,也许更好,所有在一起 -

use strict;
use warnings;
no warnings "uninitialized";
use CGI qw( :standard );

print
    header(),
    start_html("O HAI CARD");

print param("password") eq "pass" ?
    h2("Yes!") : h2({-style => "color:#a00"}, ":(");

print 
    start_form(),
    fieldset(
             legend("None Shall Pass!"),
             password_field(-name => "password",
                            -size => 25),
             submit(-value => "Submit"),
             ),
    end_form(),
    end_html();

RIF,阅读文档: CGI

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM