가끔 Perl에서 입력값을 숨기고 싶을 때가 이다.
예를 들어 DB에 access하려고 하는 스크립트를 만든다고 했을 때 스크립트에 id나 PW를 박아서 연결하거나 간단한 scanf 를 통해  값을 입력받는다.

근데 그렇게 하면 PW가 공개될 우려가 있기 때문에 이를 막아주기 위하여 IO-Prompt를 사용하여 마치 리눅스 로그인하듯이 입력값을 가릴 수 있게 할 수 있다.
===========================================================================
본시스템은 허가된 사용자만 이용하실수 있습니다.
부당한 방법으로 전산망에 접속하거나 정보를 삭제/변경/유출하는
사용자는 관련법령에 따라 처벌 받게 됩니다

This is a private computer facility.
Access for any reason must be specifically authorized by the manager.
Unless you are so authorized, your continued access and any other use may
expose you to criminaland or civil proceedings
=========================================================================== 
login: 5dolstory
Password:  

리눅스에 로그인하게 될 때 Password를 치게 되면 이 때 Password 입력값은 먹지만 실제로 화면에 보여주지는 않는다.

이걸 할 수 있는 녀석이Term-ReadPassword이다.

우선 다운받아 리눅스에 인스톨을 하자.


[root@xxxx /xxxx/perlprogram/Term-ReadPassword-0.11] perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for Term::ReadPassword
[root@xxxx /xxxx/perlprogram/Term-ReadPassword-0.11] make
cp ReadPassword.pm blib/lib/Term/ReadPassword.pm
Manifying blib/man3/Term::ReadPassword.3pm
[root@xxxx /xxxx/perlprogram/Term-ReadPassword-0.11] make install
Installing /usr/lib/perl5/site_perl/5.8.5/Term/ReadPassword.pm
Installing /usr/share/man/man3/Term::ReadPassword.3pm
Appending installation info to /usr/lib/perl5/5.8.5/i386-linux-thread-multi/perllocal.pod
[root@xxxx /xxxx/perlprogram/Term-ReadPassword-0.11]


저렇게 하면 모듈이 인스톨 된 것인다.

소스를 짜는 건 단순하다. 

#!/usr/bin/perl
use Term::ReadPassword;

print "input pw :";
$pw = read_password($_[0]);
print $pw; 


저렇게 짜고 실행을 시키면 이런 결과가 나온다.
 /.pw.pl
input pw :
aaaa 

즉 input pw : aaaa
aaaa
이렇게 출력되지 않는다는 것이다.


모듈 설명서 링크 : http://search.cpan.org/~phoenix/Term-ReadPassword-0.11/ReadPassword.pm


'서버 이야기 > Perl 이야기' 카테고리의 다른 글

Perl로 메일보낼 때 파일 첨부하기  (0) 2011.04.15
PERL FTP 파일 다운로드  (0) 2010.11.18
PERL Error Handling  (0) 2010.11.18
PERL Subrountines  (0) 2010.11.18
PERL Regular Expressions  (0) 2010.11.18
Posted by 서오석
,