use Win32::OLE qw (in); use CGI qw(:standard); $Win32::OLE::Warn = 3; print header; print start_html { title => 'Password Query' }; my $sqlserver = "SERVER_NAME"; my $database = "PASS"; my $pwdtble = "_PASSWORDS"; my $key = "AB928RQG"; my $target = param('strComputer'); # ERROR CHECKING if ($target eq ""){ print "
You must enter a computer account.

"; print "

"; print end_html; exit 1; } my $text = retrieve($target); print "

Password: $text


"; print "

"; print end_html; sub retrieve{ my $target = shift @_; use DBD::ODBC; my %history; my $DSN = "driver={SQL Server};Server=$sqlserver;database=$database"; my $dbh = DBI->connect("dbi:ODBC:$DSN") || return -1; if (not $dbh) { print "coud not connect\n"; return -1; } my $sth = $dbh->prepare("select password, date_modified from $pwdtble where computername = ?"); if ($sth->execute($target)) { while (my ($password, $date) = $sth->fetchrow()) { $history{$date} = decrypt($key,$password); } } else { return; } foreach my $date (reverse (sort (keys %history))) { return $history{$date}; } } sub decrypt{ use Crypt::TripleDES; my $key = shift @_; my $e_text = shift @_; my $des = new Crypt::TripleDES; my $text = $des->decrypt3 ( $e_text, $key ); return $text; }