在Perl中需要有关添加/检索功能的帮助 [英] Need help with add/retrieve functions in Perl

查看:90
本文介绍了在Perl中需要有关添加/检索功能的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试运行的程序中需要帮助.我是Perl的新手,并认为这是正确的,但是它不起作用.该表格允许用户输入5位数字的帐号和密码.一个必须包含6-10个字符的密码.在将密码保存到数据库之前,我必须使用tr///运算符对密码进行加密,但是,如果他们单击显示密码",则密码应该显示为未加密.有人看到我的错误吗?当我运行它时,我的程序认为我正在尝试保存另一个帐户,并向我发送add()函数中的错误消息.但是,如果用户单击告诉我密码",它甚至不应该去那里.

I need help in a program I''m trying to run. I am new to Perl and thought this was right but it''s not working. This form was to allow a user to enter a 5 digit account number & a passwd that must include 6-10 characters. I have to use the tr/// operator to encrypt the passwed before saving it to the database, however if they click "show me my password" it should display it unecrypted. Does anyone see my error? When I run it, my program thinks I''m trying to save another account and giving me the error message that''s in my add() function. But it shouldn''t even be going there if the user has clicked "Tell Me My Password".

print "Content-type: text/html\n\n";
use CGI qw(:standard);
 se SDBM_File;
use Fcntl;
 
#prevent perl from creating undeclared variables
use strict;
 
#declare variables
my ($button, $account, $password);

#assign values to variables
$button = param('Button');
$account = param('Account');
$password = param('Pass');

if(length($account) == 5){
   if ($button == "Create Account") {
        add();
   }
   elsif ($button == "Tell Me My Password") {
     retrieve();
   }
}else{
      print "<HTML>\n";
     print "<HEAD><TITLE>Books Online</TITLE></HEAD>\n";
     print "<h1>Please return to the form.</h1>\n";
     print "Enter a valid account number. \n";
     print "\n";
}
exit;
#*****user-defined functions*****

sub add {
  my %accountinfo;

  if(length($password) >= 6 && length($password) <= 10){
     tie(%accountinfo, "SBDM_File", "c09case2", O_CREAT|O_RDWR, 0666)
           or die "Error opening c09case2. $!, stopped";
     $password =~ tr/abcdefghij/1234567890/;
     $accountinfo{$account} = $password;
     untie(%accountinfo);

      #create Web page
      print "<HTML>\n";
      print "<HEAD><TITLE>Books Online</TITLE></HEAD>\n";
      print "<h1>Books Online</h1>\n";
      print "Your information has been recorded.\n";
      print "\n";
   } else {
     print "<HTML>\n";
     print "<HEAD><TITLE>Books Online</TITLE></HEAD>\n";
     print "<h1>Please return to the form.</h1>\n";
     print "Enter a valid password. \n";
     print "\n";
   }
  }# end add

sub retrieve{
   my %accountinfo;
   my $pass_info;
  tie(%accountinfo, "SBDM_File", "c09case2", O_CREAT|O_RDWR, 0666)
        or die "Error opening c09case2. $!, stopped";
  $pass_info = $accountinfo{$account};
  untie(%accountinfo);
  $pass_info =~ tr/1234567890/abcdefghij/;
   #create Web page
   print "<HTML>\n";
   print "<HEAD><TITLE>Books Online</TITLE></HEAD>\n";
   print "<h1>Your password is</h1>\n";
   print "$pass_info \n";
   print "\n";
}

推荐答案

按钮,
button,


帐户,
account,


密码); # 将值分配给变量
password); #assign values to variables


这篇关于在Perl中需要有关添加/检索功能的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆