I assume that you are using some form of database. In the DBI docs somewhere, it states that you should use placeholders for your data. For example:
# $dbh contains your database handle
my $sth = $dbh->prepare( "SELECT * FROM foo WHERE id = ? AND bar = ?"
+) or die( "Could not prepare statement: ".$dbh->errstr() ); #of cours
+e you will have a more elegant error handling method than just die
$sth->execute( $value_for_id, $value_for_bar );
#and then just fetch the data like you would normally.
Placeholders also have the added advantage of reusing your queries. For example:
#Take the same $sth from the previous example
my @data_to_query = ( #You would probably get this from somewhere else
{ id => 763, bar => "baz" },
{ id => 923, bar => "qux" },
#...and so forth
);
foreach( @data_to_query ) {
$sth->execute( $_->{id}, $_->{bar} );
#do something with that dataset
}
The advantage of that is not only performance(only need to compile SQL statement once), but the placeholders are replaced with safe data that can be used in the database. Of course, I left out several things like error handling for incorrect or malformed queries, but it is implied that you should have that.
In terms of other security, make sure you use common sense. Hash your passwords and add a salt, ensure that nobody should see data they're not supposed to see, and all other typical web security tips.
Use common sense(and common::sense) and all will be well.
~
Thomas~
confess( "I offer no guarantees on my code." );
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.