Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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 "<br><center><strong>You must enter a computer account.</str +ong></center><br>"; print "<p align='center'><input name='Close' type='button' id='Clo +se' onClick='window.close()' value='Close'></p>"; print end_html; exit 1; } my $text = retrieve($target); print "<h2>Password: $text</h2><br></center>"; print "<p><center><input type='button' value='Close' name='close' onCl +ick='window.close()'></center></p>"; print end_html; sub retrieve{ my $target = shift @_; use DBD::ODBC; my %history; my $DSN = "driver={SQL Server};Server=$sqlserver;database=$databas +e"; 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 $pwdt +ble 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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl/CGI and first query
by insaniac (Friar) on Mar 10, 2005 at 15:24 UTC |