<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Talkwards &#187; Programming</title>
	<atom:link href="http://www.talkwards.com/category/computers-and-internet/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.talkwards.com</link>
	<description>Advancing Talkwards...</description>
	<lastBuildDate>Sat, 03 Sep 2011 16:33:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How do you log to the Windows event log from C# .NET?</title>
		<link>http://www.talkwards.com/2011/05/how-do-you-log-to-the-windows-event-log-from-c-net</link>
		<comments>http://www.talkwards.com/2011/05/how-do-you-log-to-the-windows-event-log-from-c-net#comments</comments>
		<pubDate>Tue, 17 May 2011 11:34:50 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Computers and Internet]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.talkwards.com/?p=611</guid>
		<description><![CDATA[This seems to do the trick: private void logError(string message, string source) { System.Diagnostics.EventLog log = new System.Diagnostics.EventLog(); log.Source = source; log.WriteEntry(message, System.Diagnostics.EventLogEntryType.Error); log.Close(); } private void logError(Exception exception, string source) { logError(exception.ToString(), source); } Put it in your class, or in a special logging class. Read more: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=77 http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx I might add that the [...]]]></description>
			<content:encoded><![CDATA[<p>This seems to do the trick:</p>
<pre style="padding-left: 30px;">private void logError(string message, string source)
{
	System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
	log.Source = source;
	log.WriteEntry(message, System.Diagnostics.EventLogEntryType.Error);
	log.Close();
}

private void logError(Exception exception, string source)
{
	logError(exception.ToString(), source);
}</pre>
<p>Put it in your class, or in a special logging class.</p>
<p>Read more:</p>
<ul>
<li><a href="http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=77" target="_blank">http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=77</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx</a><br />
I might add that the comment about latency when creating event log sources <em>does not</em> seem to apply on Windows 2008 Server (where I tested the above code &#8211; which doesn&#8217;t even create a source&#8230; ummm)</li>
<li><a href="http://www.codeproject.com/KB/architecture/exceptionbestpractices.aspx" target="_blank">http://www.codeproject.com/KB/architecture/exceptionbestpractices.aspx</a></li>
</ul>
<div id="_mcePaste" class="mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">
<table border="0" cellspacing="0" frame="VOID" rules="NONE">
<colgroup>
<col width="199"></col>
<col width="234"></col>
<col width="161"></col>
<col width="300"></col>
</colgroup>
<tbody>
<tr>
<td width="199" height="18" align="LEFT" valign="TOP">Internt/Egna</td>
<td width="234" align="LEFT" valign="TOP">SharePoint – Miniprojekt</td>
<td width="161" align="LEFT" valign="TOP">Utveckling/Design</td>
<td width="300" align="LEFT" valign="TOP">Lookup fält programmagiskt&#8230; / ContentTypes</td>
</tr>
</tbody>
</table>
</div>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2011%2F05%2Fhow-do-you-log-to-the-windows-event-log-from-c-net&amp;title=How%20do%20you%20log%20to%20the%20Windows%20event%20log%20from%20C%23%20.NET%3F" id="wpa2a_2"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2011/05/how-do-you-log-to-the-windows-event-log-from-c-net/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Is Java pass-by-value or pass-by-reference?</title>
		<link>http://www.talkwards.com/2009/07/is-java-pass-by-value-or-pass-by-reference</link>
		<comments>http://www.talkwards.com/2009/07/is-java-pass-by-value-or-pass-by-reference#comments</comments>
		<pubDate>Fri, 17 Jul 2009 23:00:14 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.talkwards.com/?p=564</guid>
		<description><![CDATA[The question if Java passes parameters by value or by reference seems to be one of the things newcomers to the Java language stumble upon quite often. In general the answer is simple: Java is always pass-by-value. What does this mean? Pass-by-value means that you get a copy of the passed in object to work [...]]]></description>
			<content:encoded><![CDATA[<p>The question if Java passes parameters<em> by value</em> or <em>by reference</em> seems to be one of the things newcomers to the Java language stumble upon quite often.</p>
<p>In general the answer is simple: <strong>Java is always pass-by-value</strong>.</p>
<p>What does this mean?</p>
<p>Pass-by-value means that you get a <em>copy</em> of the passed in object to work with, as opposed to a reference to it.</p>
<p>Let&#8217;s exemplify.  Assume we have a method that manipulates a List object:</p>
<blockquote>
<pre>public void updateList(List list) {</pre>
<pre>    ..;</pre>
<pre>}</pre>
</blockquote>
<p>Now, assume we&#8217;d like to replace the passed-in list with another list we&#8217;ve created inside the method.  We might like to do something like:</p>
<blockquote>
<pre>public void updateList(List list) {</pre>
<pre>    List myList = new ArrayList();</pre>
<pre>    // add objects to myList</pre>
<pre>    list = myList; // replace list with my new list? <strong>*WRONG*</strong></pre>
<pre>}</pre>
</blockquote>
<p>However, if we test this new method we&#8217;ll find <strong>list</strong> has not changed at all.</p>
<p>This is because <strong>list</strong> is a copy of the object we passed-in to the method, and not the passed-in object itself.  <strong>list</strong> has been passed-by-value!</p>
<p>So, are we unable to change variables that are passed-in to a method in Java?  Can we only change them by returning a new object?</p>
<p>No.</p>
<p>And this is where the confusion sets in, because while we&#8217;re unable to replace the passed-in object <strong>list</strong> with another object, we&#8217;re perfectly allowed to <em>manipulate it&#8217;s member objects.</em></p>
<p>Basically this means if we want to replace a passed-in list with our own list we <em>must </em>do:</p>
<blockquote>
<pre>public void updateList(List list) {</pre>
<pre>    List myList = new ArrayList();</pre>
<pre>    // add objects to myList</pre>
<pre>    list.clear(); // empty passed-in list</pre>
<pre>    list.addAll(myList); // replace passed-in list with my new list!</pre>
<pre>}</pre>
</blockquote>
<p>Since we never try to replace <strong>list</strong><em> itself</em>, the whole method works just fine and does what we expect.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2009%2F07%2Fis-java-pass-by-value-or-pass-by-reference&amp;title=Is%20Java%20pass-by-value%20or%20pass-by-reference%3F" id="wpa2a_4"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2009/07/is-java-pass-by-value-or-pass-by-reference/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sun Tzu&#8217;s Art of War &#8211; Agile&#8230;</title>
		<link>http://www.talkwards.com/2009/06/sun-tzus-art-of-war-agile</link>
		<comments>http://www.talkwards.com/2009/06/sun-tzus-art-of-war-agile#comments</comments>
		<pubDate>Fri, 05 Jun 2009 23:00:59 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[agile programming]]></category>
		<category><![CDATA[programming practices]]></category>

		<guid isPermaLink="false">http://www.talkwards.com/?p=541</guid>
		<description><![CDATA[A quote from the Art of War that might have some baring on Agile development techniques: 31. Water shapes its course according to the nature of the ground over which it flows; the soldier works out his victory in relation to the foe whom he is facing. 32. Therefore, just as water retains no constant [...]]]></description>
			<content:encoded><![CDATA[<p>A quote from the Art of War that might have some baring on Agile development techniques:</p>
<blockquote><p>31. Water shapes its course according to the nature<br />
of the ground over which it flows; the soldier works<br />
out his victory in relation to the foe whom he is facing.</p>
<p>32. Therefore, just as water retains no constant shape,<br />
so in warfare there are no constant conditions.</p></blockquote>
<p>But then again, we all know war is agile, right?</p>
<p>Or another quote I heard (source unknown, original language Swedish):</p>
<blockquote><p>Meeting all requirements in programming is like walking on water.  It&#8217;s easy if the water and the requirements are frozen&#8230;</p></blockquote>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2009%2F06%2Fsun-tzus-art-of-war-agile&amp;title=Sun%20Tzu%26%238217%3Bs%20Art%20of%20War%20%26%238211%3B%20Agile%26%238230%3B" id="wpa2a_6"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2009/06/sun-tzus-art-of-war-agile/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CHARVA: A Java Windowing Toolkit for Text Terminals</title>
		<link>http://www.talkwards.com/2008/11/charva-a-java-windowing-toolkit-for-text-terminals</link>
		<comments>http://www.talkwards.com/2008/11/charva-a-java-windowing-toolkit-for-text-terminals#comments</comments>
		<pubDate>Fri, 28 Nov 2008 22:00:54 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[user interface (ui)]]></category>

		<guid isPermaLink="false">http://www.talkwards.com/?p=430</guid>
		<description><![CDATA[Looking around for an easy way to create applications with text GUIs for running over SSH terminals I came across CHARVA. CHARVA&#8217;s API copies Swings, it unfortunately is not built on top of Swing but is a copy of Swing. This forces implementers to import classes in the charva.awt and charvax.swing packages instead of traditional [...]]]></description>
			<content:encoded><![CDATA[<p>Looking around for an easy way to create applications with text GUIs for running over SSH terminals I came across <a href="http://www.pitman.co.za/projects/charva/index.html" target="_blank">CHARVA</a>. CHARVA&#8217;s API copies Swings, it unfortunately is not built on top of Swing but is a copy of Swing.  This forces implementers to import classes in the charva.awt and charvax.swing packages instead of traditional awt and swing classes.  However, the result is rather nice, at least if you&#8217;re looking to run applications off a server on a simple Point-of-Sale or Point-of-Service (POS) terminal that may not even support graphics.</p>
<p>In my case I&#8217;m looking into making a simple app that I can use to keep track of passwords, both when I&#8217;m at home (regular swing) and when I&#8217;m away (at work or similar) and only able to access the application via SSH (CHARVA).</p>
<p>For more info, check out CHARVA here: <a href="http://www.pitman.co.za/projects/charva/index.html" target="_blank">http://www.pitman.co.za/projects/charva/index.html</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2008%2F11%2Fcharva-a-java-windowing-toolkit-for-text-terminals&amp;title=CHARVA%3A%20A%20Java%20Windowing%20Toolkit%20for%20Text%20Terminals" id="wpa2a_8"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2008/11/charva-a-java-windowing-toolkit-for-text-terminals/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling to different versions of Java in Eclipse</title>
		<link>http://www.talkwards.com/2008/11/compiling-to-different-versions-of-java-in-eclipse</link>
		<comments>http://www.talkwards.com/2008/11/compiling-to-different-versions-of-java-in-eclipse#comments</comments>
		<pubDate>Fri, 21 Nov 2008 22:00:50 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Computer Architecture]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Apache Tomcat]]></category>
		<category><![CDATA[configuration management]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[runtime errors]]></category>

		<guid isPermaLink="false">http://www.talkwards.com/?p=440</guid>
		<description><![CDATA[I&#8217;ve just had the rather unsettling experience of trying to deploy a new jar file (one I recompiled after some changes). This file were to be deployed on a rather old set up of Java 1.4.2. On first try everything broke with the classic &#8220;Unsupported major.minor version 50.0&#8243;. So I went back to the drawing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just had the rather unsettling experience of trying to deploy a new jar file (one I recompiled after some changes).  This file were to be deployed on a rather old set up of Java 1.4.2.  On first try everything broke with the classic &#8220;Unsupported major.minor version 50.0&#8243;.</p>
<p>So I went back to the drawing board.  I installed java 1.4, and made sure my development Tomcat was running it.  Then I did some research and found out how to make Eclipse compile 1.4 compliant code.  I started and I got the same error still.</p>
<p>Once I figured out what was wrong I realized I was an idiot (Doh!).  The error I&#8217;ve gotten wasn&#8217;t for any file part of the jar I was trying to deploy but for &#8220;index_jsp&#8221;.  The thing is my Tomcat compiled my JSP:s into class files and never looked at them again until they were changed.  I am sure there&#8217;s several ways to solve the problem, I just went and deleted the files in the &#8220;work&#8221;-directory (those pertaining to my Context).</p>
<div id="attachment_442" class="wp-caption alignright" style="width: 310px"><a href="http://www.talkwards.com/wp-content/uploads/2008/11/eclipse-source-target-versions.png"><img class="size-medium wp-image-442" title="The Eclipse preferences window" src="http://www.talkwards.com/wp-content/uploads/2008/11/eclipse-source-target-versions-300x269.png" alt="The preferences window for setting source and target versions for java compilation" width="300" height="269" /></a><p class="wp-caption-text">The preferences window for setting source and target versions for Java compilation</p></div>
<p>Now over to how to make Eclipse code projects to a certain Java version.</p>
<p>There are two values you will want to keep track of.  The source version and the target version.  The source version tells what version your source code is written in.  Whereas the target version tells what version of Java you want your class files in.</p>
<p>If for instance you have a project written in Java 1.4 source style, but you have to run it on a Java 5 you&#8217;d set the source version to 1.4 and the target to 1.5. You are now compiling Java 1.4 source into Java 5 class files.  Unfortunately you&#8217;re not able to do the opposite, compile Java 5 source code into Java 1.4 class files.  This is probably due to API incompatibilities, Java 5 has a larger API than Java 1.4.</p>
<p>Now, in Eclipse you have two settings in three places that controls the source and target versions of your compilations.  Under Window-&gt;Preferences-&gt;Java-&gt;Compiler (Eclipse 3.4) you&#8217;re able to set the versions for the whole IDE.</p>
<p>When you create a new project you&#8217;re able to determine what version of Java (source and target you want) and right clicking on a project and choosing Properties-&gt;Java Compiler, you have the same dialog as before.</p>
<p>You set the target level in the select box &#8220;Compiler compliance level&#8221;, and optionally by unchecking the &#8220;Use default compliance settings&#8221; you&#8217;re able to change the target (&#8220;Generated .class files compatibility&#8221;) and source respectively.</p>
<p>If you experience other problems you may want to &#8220;clean&#8221; your project(s).  Cleaning a project means all compiled files are removed and all source files are recompiled (something the IDE will do by itself when you change compilation versions, but if you want to be sure, you can do it manually).  This is done by choosing Project-&gt;Clean.  In the dialog you can chose to clean all projects or just those you select.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2008%2F11%2Fcompiling-to-different-versions-of-java-in-eclipse&amp;title=Compiling%20to%20different%20versions%20of%20Java%20in%20Eclipse" id="wpa2a_10"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2008/11/compiling-to-different-versions-of-java-in-eclipse/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Injections, the two most common types</title>
		<link>http://www.talkwards.com/2008/11/sql-injections-the-two-most-common-types</link>
		<comments>http://www.talkwards.com/2008/11/sql-injections-the-two-most-common-types#comments</comments>
		<pubDate>Fri, 14 Nov 2008 22:00:03 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Computer Architecture]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL-injections]]></category>
		<category><![CDATA[web programming]]></category>

		<guid isPermaLink="false">http://www.talkwards.com/?p=434</guid>
		<description><![CDATA[What is an SQL-injection. How can it affect my site. How does it happen and how can I avoid it? Since Firefox (2 and 3) and MSIE 7 started using Google&#8217;s (and others) system for blocking sites that produce harmful web pages the problem with SQL-injections have been put on the spot. What happens is [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_471" class="wp-caption alignright" style="width: 310px"><a href="http://www.talkwards.com/wp-content/uploads/2008/11/reported-attack-site.png"><img class="size-medium wp-image-471" title="Reported Attack Site" src="http://www.talkwards.com/wp-content/uploads/2008/11/reported-attack-site-300x203.png" alt="Opening a site Google has listed as spreading malicious software via the browser." width="300" height="203" /></a><p class="wp-caption-text">Opening a site Google has listed as spreading malicious software via the browser.</p></div>
<p>What is an SQL-injection.  How can it affect my site.  How does it happen and how can I avoid it?</p>
<p>Since Firefox (2 and 3) and MSIE 7 started using Google&#8217;s (and others) system for blocking sites that produce harmful web pages the problem with SQL-injections have been put on the spot.</p>
<p>What happens is that an attacker hacks a site by placing their own SQL-code into the database of the victim system.  Instead of just performing a DOS (<a href="http://en.wikipedia.org/wiki/Denial_of_service" target="_blank">denial of service</a>) attack bringing the whole site down by for instance deleting all the tables or doing something else harmful to the site the attacker plants client side browser code in the database making all visitors run client side code that will infect their computer with a virus.  This virus may do everything from listening in on traffic between the client (web browser) and bank applications, to connecting the client system to a <a href="http://en.wikipedia.org/wiki/Bot_net" target="_blank">botnet</a>.</p>
<p>Needless to say, the SQL-injection attack has become a problem not so much for the owner of the originally defunct site as for the visitors to said site.  (Although users of the web should not underestimate the consequence of a good virus protection, system update policy and secure browsing policy).</p>
<p>Since the owner of the vulnerable software won&#8217;t notice any detour from business as usual (and neither will most infected clients), nobody is the wiser to the problem.</p>
<p>This is why Google (and others) have started evaluating (and flagging) sites with bad content, and why Firefox and MSIE (and probably others) have started blocking them.</p>
<p><span id="more-434"></span></p>
<h4>What is an SQL-injection?</h4>
<p>The short explanation (hinted above) is that an <a href="http://en.wikipedia.org/wiki/SQL_injection" target="_blank">SQL-injection</a> is an attack where the attacker inserts their own SQL code into the attacked system, and thus alters the database content of the attacked system.  Either wrecks havoc by destroying part of or the whole system, or by inserting virus spreading code onto the pages of the attacked site (if their content is stored in the database).</p>
<h4>How is an SQL-injection attack performed?</h4>
<p>There are two major ways of doing this (and in order to follow this part of the conversation you will need to know a bit of SQL).</p>
<p>The first method of performing an SQL-injection is by manipulating the input to different kinds of forms on the site (search forms, contact forms, and other places where the user can put information into the system).</p>
<p>To understand this attack you need a basic understanding of SQL.</p>
<p>Imagine we have a database table with products, each having a color, and we want to list all products that are &#8216;green&#8217;.  This would be done with the following question:</p>
<blockquote>
<pre>SELECT * FROM products WHERE color = 'green';</pre>
</blockquote>
<p>Each database command is ended with a semicolon (;), and all literal strings are enclosed by single quotes (&#8216;).  So issuing two commands in a row would look something like:</p>
<blockquote>
<pre>SELECT * FROM products WHERE color = 'green';
UPDATE products SET hasBeenSearchedFor = 'true' WHERE color = 'green';</pre>
</blockquote>
<p>Notice the semicolons and the single quotes.  You do not need to understand what the commands do in order to understand the rest.</p>
<p>Now imagine that we get the value &#8216;green&#8217; from an application the user can input data into.  As long as the user types things like green, red, blue everything is safe, but what would happen if the user typed in the following as a color?</p>
<blockquote>
<pre>'; do harmful thing to database; '</pre>
</blockquote>
<p>In an unprotected system the SQL-string is usually tacked together one part after the other without checking if the search parameter is valid or sane.  Imagine the search command is built in the following way (double quotes are used in most systems to create strings, they are not to be confused with the single quotes of the database query):</p>
<blockquote>
<pre>sql = "SELECT * FROM products WHERE color = '" + colorValue + "'";</pre>
</blockquote>
<p>Now if a user would put the above value into the color search (placing it in &#8220;colorValue&#8221;) the value of the sql string (and what would be passed on to the database would be):</p>
<blockquote>
<pre>"SELECT * FROM products WHERE color = '" +
          "'; do harmful thing to database; '" + "'"</pre>
</blockquote>
<p>This in turn would evaluate to:</p>
<blockquote>
<pre>SELECT * FROM products WHERE color = ''; do harmful thing to database; ''</pre>
</blockquote>
<p>I.e. select all products with an empty color value, then &#8220;do harmful thing to database&#8221;.  After that the SQL-server will encounter the empty quotes and issue an error.</p>
<p>If the database question is executed in a transaction all changes will be rolled back, however this is a rather weak defense against SQL-injections since it is possible to input values that will create three valid commands easily.  (I&#8217;ll leave that up to the fantasy of the reader!)</p>
<p>The second way of performing an SQL-injection attack is to tack on values to numerical input to the system.  Pages that display products, user profiles, or any other information easily mapped to a row in a database table are usually candidates for this kind of attack.</p>
<p>Imagine a page that displays a product profile.  It might be called with the following URL:</p>
<blockquote>
<pre>http://www.mysite.com/showProduct?productid=123</pre>
</blockquote>
<p>The &#8220;productid&#8221; value will then be passed on to make the following database question:</p>
<blockquote>
<pre>sql = "SELECT * FROM products WHERE id = " + productid;</pre>
</blockquote>
<p>Here the attacker does not even have to add a single quote to get an extra SQL-command.  All they need to do is add a trailing &#8220;;&#8221; and they&#8217;re in.  The only complicating factor is that the URL used to call the system will have to be URL-encoded in order for this attack to work, but that&#8217;s far from a problem even for an unskilled attacker.</p>
<h4>How do you protect against SQL-injections?</h4>
<p>The key concept is: never, NEVER, <strong>NEVER</strong>, trust input from a user!</p>
<p>That&#8217;s right.  NEVER TRUST THE USER.</p>
<p>Don&#8217;t ask what-if a user tries to gain access to our system.</p>
<p>Say WHEN the user tries to gain access to our system, then we&#8217;re gonna&#8230;.</p>
<p>The short, technical answer (for Java, .NET and similar languages) is to NEVER build SQL-strings like shown above.  Use &#8220;prepared statements&#8221; or similar constructs where the input variables can be tested by JDBC (or ADODB or LINQ or similar framworks).</p>
<p>Another safe way to go is to use stored procedures.  These are not just optimized for speed and performance, they are also, almost always strongly typed, disallowing the kind of problems displayed above.</p>
<p>If neither of these are feasible always make sure the input&#8217;s single quotes are filtered away or &#8220;escaped&#8221;.  Escaping a single quote means that all databases have support for using single quotes as values in a table column, if you prepend them with a backslash (\) or use double single quotes (&#8221;, that&#8217;s two single quotes).  Do this programatically before sending the data on to the database.</p>
<p>Protecting against attacks on pages with numerical input is even simpler.  If there&#8217;s a number input value, make sure it is numerical by translating it into a number before passing it on to the database (input from web applications are almost always sent as strings, but if a value should be a number, make sure it is!)</p>
<p>Part from this a sound backup and restore policy is a sure way to not only protect hours of time invested in putting information into the system but the users trust in the system, and the time it will take to get a blocked site back up on its feet.</p>
<p>Read more about SQL-injections here: <a href="http://en.wikipedia.org/wiki/SQL_injection" target="_blank">http://en.wikipedia.org/wiki/SQL_injection</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2008%2F11%2Fsql-injections-the-two-most-common-types&amp;title=SQL%20Injections%2C%20the%20two%20most%20common%20types" id="wpa2a_12"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2008/11/sql-injections-the-two-most-common-types/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search and Replace in MySQL</title>
		<link>http://www.talkwards.com/2008/11/search-and-replace-in-mysql</link>
		<comments>http://www.talkwards.com/2008/11/search-and-replace-in-mysql#comments</comments>
		<pubDate>Fri, 07 Nov 2008 22:00:24 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[DBMS]]></category>
		<category><![CDATA[DML]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.talkwards.com/?p=417</guid>
		<description><![CDATA[I&#8217;ve come across a problem in one of my projects at work. It consists of searching and replacing data in a MySQL server. The data to be replaced is an old URL used in lots of text fields all over the place, it is the customers own site URL but since they moved, they now [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve come across a problem in one of my projects at work.  It consists of searching and replacing data in a MySQL server.  The data to be replaced is an old URL used in lots of text fields all over the place, it is the customers own site URL but since they moved, they now want all URLs to point to their new location.</p>
<p>Searching the web and checking up the <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace" target="_blank">MySQL function database</a> returns the following useful command:</p>
<blockquote>
<pre>REPLACE(str, from_str, to_str)</pre>
</blockquote>
<p>It would in my case be used like this:</p>
<blockquote>
<pre>UPDATE myTable SET theTextField =
REPLACE(theTextField, 'http://the.old.site', 'http://the.new.site');</pre>
</blockquote>
<p><code>myTable</code> is the table containing the data I want to replace, <code>theTextField</code> is the exact field in which this data is located.  Obviously &#8220;http://the.old.site&#8221; is the existing information, that I want to replace, and &#8220;http://the.new.site&#8221; is the information this string should be replaced with.</p>
<p>Very simple, very elegant.  Now all I have to do is try it out as well.  (Expect more reports on the progress of this work!)</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2008%2F11%2Fsearch-and-replace-in-mysql&amp;title=Search%20and%20Replace%20in%20MySQL" id="wpa2a_14"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2008/11/search-and-replace-in-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open UP</title>
		<link>http://www.talkwards.com/2008/10/open-up</link>
		<comments>http://www.talkwards.com/2008/10/open-up#comments</comments>
		<pubDate>Fri, 10 Oct 2008 22:00:25 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[development process]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[unified process]]></category>
		<category><![CDATA[up]]></category>

		<guid isPermaLink="false">http://www.hoakz.com/blog/?p=255</guid>
		<description><![CDATA[Anybody who ever came into contact with RUP (which is the name of Rational&#8217;s &#8212; now IBM&#8217;s &#8212; version of the Unified Process) may have stumbled upon their web application created to support the process. In there you can find work flows, actor and artifact definitions, templates etc etc. I did, come across it some [...]]]></description>
			<content:encoded><![CDATA[<p>Anybody who ever came into contact with <a href="http://sv.wikipedia.org/wiki/Rational_Unified_Process" target="_blank">RUP</a> (which is the name of Rational&#8217;s &#8212; now IBM&#8217;s &#8212; version of the <a href="http://en.wikipedia.org/wiki/Unified_process" target="_blank">Unified Process</a>) may have stumbled upon their web application created to support the process.  In there you can find work flows, actor and artifact definitions, templates etc etc.</p>
<p>I did, come across it some ten or so years ago.  Since then I&#8217;ve had the (mis)fortune to work at companies with their own &#8220;UP&#8221; or what-have-you-versions of development processes.  However, imagine my surprise and delight when I came across an <a href="http://epf.eclipse.org/wikis/openup/" target="_blank">Open version of UP</a> (sponsored by the Eclipse project) with the web application, the actors and templates and all.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2008%2F10%2Fopen-up&amp;title=Open%20UP" id="wpa2a_16"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2008/10/open-up/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Has the Large Hadron Collider destroyed the world yet?</title>
		<link>http://www.talkwards.com/2008/09/has-the-large-hadron-collider-destroyed-the-world-yet</link>
		<comments>http://www.talkwards.com/2008/09/has-the-large-hadron-collider-destroyed-the-world-yet#comments</comments>
		<pubDate>Mon, 15 Sep 2008 22:00:33 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[programming humor]]></category>

		<guid isPermaLink="false">http://www.hoakz.com/blog/?p=198</guid>
		<description><![CDATA[You may have heard of the Large Hadron Collider or perhaps concerns about its safety, and if not you may still have come across this funny web page to test if it has destroyed the world yet. Check the source for the last one as well, there are a few laughs. Their test to see [...]]]></description>
			<content:encoded><![CDATA[<p>You may have heard of the <a title="Wikipedia: Large Hadron Collider" href="http://en.wikipedia.org/wiki/Large_Hadron_Collider" target="_blank">Large Hadron Collider</a> or perhaps <a title="Wikipedia: Safety of the Large Hadron Collider" href="http://en.wikipedia.org/wiki/Safety_of_the_Large_Hadron_Collider" target="_blank">concerns about its safety</a>, and if not you may still have come across this funny web page to <a title="Has the Large Hadron Collider destroyed the world yet?" href="http://hasthelargehadroncolliderdestroyedtheworldyet.com/" target="_blank">test if it has destroyed the world yet</a>.</p>
<p>Check the source for the last one as well, there are a few laughs.  Their test to see if the world has ended is:</p>
<blockquote>
<pre id="line1">if (!(typeof worldHasEnded == "undefined")) {
    document.write("YUP.");
} else {
    document.write("NOPE.");
}</pre>
</blockquote>
<p>If the undefined variable worldHasEnded is not &#8220;undefined&#8221; then there&#8217;s some really spooky stuff going on&#8230; like the end of the world&#8230; otherwise we&#8217;re all safe and sound.  In the same spirit I&#8217;m offering a test for world destruction for Java (and possibly C++ and other object oriented languages as well):</p>
<blockquote>
<pre>System.out.print("Has the Large Hadron Collider destroyed the world yet? ");
if (this == null) {
    System.out.println("Yes!");
}
else {
    System.out.println("Nope");
}</pre>
</blockquote>
<p>Is the object running this test not existing any more&#8230; then risk is neither is the rest of the world&#8230;</p>
<p>Of course, we&#8217;ll have to wait until sometime in the end of October or beginning of November before they actually start colliding protons&#8230; and then perhaps the world will end&#8230;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2008%2F09%2Fhas-the-large-hadron-collider-destroyed-the-world-yet&amp;title=Has%20the%20Large%20Hadron%20Collider%20destroyed%20the%20world%20yet%3F" id="wpa2a_18"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2008/09/has-the-large-hadron-collider-destroyed-the-world-yet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DoNothing and numerical dyslexia</title>
		<link>http://www.talkwards.com/2007/10/donothing-and-numerical-dyslexia</link>
		<comments>http://www.talkwards.com/2007/10/donothing-and-numerical-dyslexia#comments</comments>
		<pubDate>Thu, 25 Oct 2007 02:07:52 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://www.hoakz.com/blog/?p=91</guid>
		<description><![CDATA[Small beauties in programming&#8230; and not all of them are made up either ;o) DoNothing: function DoNothing() { Nothing(); } Find one error: private static final int TWENTYFOUR = 24; private static final int THIRTYEIGHT = 32; private static final int FOURTYTWO = 42;]]></description>
			<content:encoded><![CDATA[<p>Small beauties in programming&#8230; and not all of them are made up either ;o)</p>
<p>DoNothing:</p>
<blockquote><p>function DoNothing() {<br />
Nothing();<br />
}</p></blockquote>
<p>Find one error:</p>
<blockquote><p>private static final int TWENTYFOUR = 24;<br />
private static final int THIRTYEIGHT = 32;<br />
private static final int FOURTYTWO = 42;</p></blockquote>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2007%2F10%2Fdonothing-and-numerical-dyslexia&amp;title=DoNothing%20and%20numerical%20dyslexia" id="wpa2a_20"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2007/10/donothing-and-numerical-dyslexia/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

