如果他們登錄成功,我需要打印他們的工資支票數據,我正在進行一項工作,我必須讓用戶登錄(根據文件檢查他們的用戶名/密碼)它存儲在另一個名爲IN-accounting.data的文件中。我設法讓用戶登錄部分工作,但我無法打印「paycheck」部分,因爲它現在它將在會計文件中打印每個人,我可以使用一些幫助瞭解如何僅打印數據用戶登錄了任何建議? 所有SSN,電話號碼,在這些文件和代碼的地址和人是假的,他們提供給做作業perl用戶登錄然後打印他們的工資支票數據
12年11月6日更新,以反映建議的更改,現在運行得數據順便我本來也想
#!/usr/bin/perl
use warnings;
use strict;
use Digest::MD5 'md5_hex';
open (PSWD, '<', 'password.passwd');
#getting username and password
#converting username to lowercase if username is entered in CAPS
print "Please enter your username: ";
chomp(my $userN = <STDIN>);
my $username = lc($userN);
############################################
print "Please enter your password: ";
chomp(my $password = <STDIN>);
my $passwd=md5_hex($password);
###############################################
my $matchCount = 0;#used later to make sure username and password match file
#reading password.passwd and assigning values
while (my $lines = <PSWD>){
my($user,$pswd,$userID,$groupID,$info,$home,$shell) = split ':', $lines;
#checking username entered vs that in the passwd file
if ($username eq $user){
print "Checking username... MATCH\n";
$username=$info;
#keeps track if username matches or not
$matchCount+=1;
#checking password entered vs that in the passwd file
if ($passwd eq $pswd){
print "Checking password... MATCH\n";
my ($first,$last)=split(" ", $info);
accounting($first,$last);
}
else{
print "Password does not match!\n";
}
last;
}
}
# if matchcount did not change, username did not match killing the program
if ($matchCount == 0){
die ("\"$username\" does not match any users in our database!\n");
}
sub accounting{
my $first_name=shift;
my $last_name=shift;
open(my $fh, '<', 'IN-accounting.data') or die "cannot open accounting file $!";
while (my $lines = <$fh>){
chomp $lines;
my @fields = split(/\|/, $lines);
push @data2, \@fields;
my($Lname,$Fname,$ssn,$address)=($fields[0],$fields[1],$fields[2],$fields[3]);
my($city,$state,$zip,$payDate)=($fields[4],$fields[5],$fields[6],$fields[7]);
my($hours,$rate,$taxes,$deductions,$notes)= ($fields[8],$fields[9],$fields[10],$fields[11],$fields[12]);
next if $Lname ne $last_name and $Fname ne $first_name;
my ($Gpay)= eval($hours)*eval($rate);#gross pay
my ($Tpay)=$Gpay-($taxes+$deductions);#total pay
my $Essn=substr($ssn,+-4);#edited ssn
print "$Fname $Lname\n";
print "$address\n";
print "$city $state $zip\n";
print "SSN: xxx-xx-$Essn\n";
print"\n";
print "Pay Date: $payDate";
print"\n";
print"You had $hours hours at \$$rate/hour\n";
print"Gross Pay: $Gpay\n";
print"Taxes:\$-$taxes\n";
print"Deductions:\$-$deductions\n";
print"Total Pay: $Tpay\n";
print"\n";
print"Notes:$notes\n\n";
}
print"press enter to quit: ";
my $quit=<>;
if ($quit){ exit;}
}
password.passwd
amon9640:4cb9c8a8048fd02294477fcb1a41191a:500:25:亞歷山大週一:/首頁/工資:/ bin中/ PA yroll iart1373:4cb9c8a8048fd02294477fcb1a41191a:501:25:伊尼戈Arterbury:/首頁/工資:/斌/工資 wher0210:4cb9c8a8048fd02294477fcb1a41191a:502:25:沃德爾赫爾曼:/首頁/工資:/斌/工資
會計文件
星期一|亞歷山大| 815-19-9640 | 4662 Dewy細分| Owltown |俄勒岡| 97434-8480 | 1/18/1998 | 19 | 21.68 | 60.28 | 2.24 |工資覈算審計帳戶,並且報告將到期不久。
Arterbury | Inigo | 037-30-1373 | 987 Rocky Island Byway |聖誕節城市|新墨西哥| 88023-3889 | 4/1/1993 | 9 | 7.02 | 17.75 | 12.71 |審計完成。發現缺陷。
Herman | Wardell | 114-29-0210 | 5555 Cinder Forest Wynd | White Eyes Town |華盛頓| 98707-5628 | 10/0/2003 | 37 | 3.07 | 41.90 | 20.89 |審覈完成。發現缺陷。
誰將使用此腳本?如果它是與會計文件相同系統上的用戶,則它們既可以訪問腳本也可以訪問文件,否則腳本將無法運行。他們只能讀取文件或從腳本中刪除密碼檢查 – JRideout
MD5是用於密碼的可怕哈希值:[加密哈希函數不是密碼哈希函數](http://throwingfire.com/storing-passwords-securely/# notpasswordhashes) – JRideout
從用戶的應用程序邏輯中分離出數據的加載和解析可能是一個好主意,它登錄並格式化輸出記錄。將數據放入某種關係數據庫也可能是一種改進 - 它們是爲這種類型的事情而構建的。 – JRideout