2012-11-15 5 views
-1

성공적으로 로그인하면 월급 데이터를 인쇄해야하는 경우 사용자가 로그인해야하는 임무 (파일에 대한 사용자 이름/비밀번호 확인)가 필요합니다. IN-accounting.data라는 다른 파일에 저장됩니다. ive는 부분적으로 작동하는 사용자 로그를 얻지 만, 이제는 회계 장부에있는 모든 것에 대해 인쇄 할 것이므로 "봉급 지불"부분을 인쇄하는 데 어려움을 겪고 있습니다. 나는 단지 데이터를 인쇄하는 방법을 알아 내는데 도움이 될 수 있습니다. 사용자가 제안 사항에 로그인 했습니까? 이러한 파일과 코드 모든 사회 보장 번호 (SSN), 전화 번호, 주소, 사람들은 할당 이 perl 사용자 로그인 후 월급 데이터 인쇄

가 11-6-12는 제안 된 변경 사항을 반영하기 위해 업데이트, 지금 실행


을 제공 데이터 만있어, 가짜 4cb9c8a8048fd02294477fcb1a41191a : 500 : 25 : 알렉산더 월요일 :/홈/급여/빈/PA 방식은 원래는


#!/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에 원 yroll iart1373 : 4cb9c8a8048fd02294477fcb1a41191a : 501 : 25 : 이니 Arterbury :/홈/급여/빈/급여 wher0210 : 4cb9c8a8048fd02294477fcb1a41191a : 502 : 25 : 워델 허먼 :/홈/급여/빈/급여

회계 파일

월요일 | Alexander | 815-19-9640 | 4662 Dewy 세분 | Owltown | 오레곤 | 97434-8480 | 1/18/1998 | 19 | 21.68 | 60.28 | 2.24 | 급여 전문가가 계정을 감사하고 있습니다. 곧.

Arterbury | 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 | 감사가 완료되었습니다. 결함이 발견되었습니다.

+0

누가이 스크립트를 사용합니까? 는 회계 파일과 같은 시스템의 사용자 인 경우, 그들은 이미 스크립트 파일 또는 다른 스크립트가 실행되지 않을 수 모두에 액세스 할 수 있습니다. ([암호화 해시 기능은 암호 해시 함수 수 없다] http://throwingfire.com/storing-passwords-securely/# : 그들은 단지 파일을 읽거나 스크립트 – JRideout

+0

MD5에서 확인 암호를 삭제할 수 있습니다 암호를 사용하는 무시 무시한 해시입니다 notpasswordhashes) – JRideout

+0

아마에 로그인하는 사용자의 애플리케이션 로직 및 서식 출력 기록에서 데이터의 로딩 및 분석을 분리하는 것이 좋습니다 것입니다. 또한 일종의 관계형 데이터베이스에 데이터를 배치하는 것이 개선 될 수 있습니다. 이러한 유형의 데이터 만 위해 작성됩니다. – JRideout

답변

0

보안 문제은 건너 뜁니다. 몇 가지를 살펴 보겠습니다.

accounting 서브 루틴은 무엇을하고 있습니까? 사용자의 월급을 인쇄 하시겠습니까? 서브 루틴에 어떤 데이터도 전달하지 않습니다. 서브 루틴은 어떤 사용자의 월급이 인쇄되는지 어떻게 알 수 있습니까?

왜 이렇게하지 않습니까?

accounting($Fname, $Lname); 

sub accounting { 
    my $first_name = shift; 
    my $last_name = shift; 

    if (not $first_name or not $last_name) { 
     die "You need a first name and a last name...) 
    } 

지금, 당신은 어디 $first_name$last_name 일치하는 라인을위한 라인으로 당신의 회계 파일 라인을 통해 루프를 찾고 있습니다.

while (my $lines = <$fh>){ 
    chomp $lines; 

    my ($Lname, $Fname, $ssn, $address, 
     $city, $state, $zip, $payDatek, 
     $hours, $rate, $taxes,$deductions, $notes) = split /\|/, $lines; 

     #Skip over non matching lines 
     next if $Lname ne $last_name and $Fname ne $first_name; 

코드에 약간의 위변조 오류가 있습니다. 몇 가지 간단한 것들 내가주의 : 당신은 배열로 배열의 참조를 추진하고있어

  • push @data2, \@fields;.
  • my ($Lname, $Fname, ... $notes) = %fields; 필드는 해시가 아닌 배열입니다.

나는이 문제로 컴파일 된 프로그램에 놀랐습니다.

그리고 코드에서 공백을 사용하십시오. 그것은 읽고 따르기가 훨씬 쉬워집니다.

+0

와우 내가 어떻게 내가 내 서브 루틴에 아무것도 전달되지 않았 음을 볼 수없는 바보 같은 생각 하는가를 만들 때 여기에 접근하는 것이 좋습니다? 그것을 지적 해 주셔서 감사합니다, 모든 것을 바로 잡는 일을 시작하고 모든 일이 어떻게 진행되는지 알려주세요. – user1819703

0

와우, 접근법에는 심각한 보안 문제가 있습니다. 나는 주석에서 몇 가지를 시도해 보겠다.

특정 질문에 초점을 맞추려면 사용자를 회계 데이터에 연결 한 다음 사용자별로 필터링해야합니다. 이상적으로는 원시 데이터를 관계형 제약이있는 데이터베이스로 가져와이 작업을보다 쉽게 ​​수행 할 수 있습니다. 반환 된 정규식 필드에 변수 이름의 매핑 후

next unless "$Fname $Lname" eq $username; 

장소이 :하지만 현재의 접근 방식에 대해 당신이 뭔가를 할 수 있습니다.