<?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>Developer&#039;s Corner</title>
	<atom:link href="http://www.developer-corner.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.developer-corner.com</link>
	<description>public Blog DevCorner {get;}</description>
	<lastBuildDate>Fri, 23 Apr 2010 07:29:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Choosing a web color scheme</title>
		<link>http://www.developer-corner.com/tech-area/choosing-a-web-color-scheme/</link>
		<comments>http://www.developer-corner.com/tech-area/choosing-a-web-color-scheme/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 07:26:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[Tech Area]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA["color scheme" "web design"]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/tech-area/choosing-a-web-color-scheme/</guid>
		<description><![CDATA[When designing a web site, on of the problems I face with is how to choose colors. Usually I choose a base color, which is the predominant color used in the web design, but how to choose other colors, such as background, headings, panels, borders and so on?]]></description>
			<content:encoded><![CDATA[<p align="left">
<p>When designing a web site, on of the problems I face with is how to choose colors. Usually I choose a base color, which is the predominant color used in the web design, but how to choose other colors, such as background, headings, panels, borders and so on?</p>
<p>My favorite tools for web design are Photoshop and Expression Design 2, plus Expression Web 2 and TopStyle for CSS/HTML editing. Topstyle has a nice feature in its color picker: given a color it suggests the complementary color</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image11.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="TopStyle - Complementary color." src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image11_thumb.png" width="397" height="372" /></a></p>
<p>and the harmonious colors:</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_10.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Topstyle - Harmonious colors" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_4.png" width="393" height="372" /></a>&#160; </p>
<h2>Basics of color theory</h2>
<p>The <strong>opposite </strong>or <strong>complementary color </strong>is defined in wikipedia as &quot;<em>the color that is of opposite hue in some color model</em>&quot;. Given a color wheel, and chosen a color, the opposite color is the one at the opposite side of the wheel. For example, the opposite color of the red in the following wheel is the green:</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_12.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="The color wheel" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_5.png" width="343" height="339" /></a> </p>
<p>If you are wondering what a color wheel is, it&#8217;s a set of colors hues around a circle. The nice thing about the color wheel is that theoretically any set of colors chosen from the color wheel &quot;will look good together&quot;. <strong>Harmonious colors</strong> are colors having a fixed relation in the color wheel. For instance, a <em>square color harmony </em>is made up of four colors equally spaced in the color wheel:</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_14.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Square color scheme" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_6.png" width="333" height="333" /></a> </p>
<p>There are several other color schemas, such as complementary, triadic and rectangular.</p>
<p>I don&#8217;t want to discuss further on color theory as honestly I don&#8217;t feel an expert in this area. There are better resources to look for more info, just google for &quot;color theory&quot; and you will get several valuable introductions.</p>
<h2>Back to TopStyle and introduction to color schemer tools</h2>
<p>After this very brief introduction to color theory, let&#8217;s get back to TopStyle, the CSS/HTML editor. While using it, I wondered: <em>isn&#8217;t there any tool to help me choose a good color scheme</em>? The answer is, of course, yes. There are several tools, most of them are web based and free, others are downloadable and installable products, usually commercial products. As a matter of preference, I like to work with tools installed on my workstation, even if I have to pay a price, and if the tool is worth the price I pay for. So, after googling, trying and discarding several products, I came to the one I currently use.</p>
<p>Its name is <a title="ColorImpact" href="http://www.tigercolor.com/ColorImpact.asp" target="_blank">ColorImpact</a>, a features-rich application providing a color wheel to choose the colors from, plus a set of other useful tools I&#8217;m going to describe.</p>
<p>At program startup the main window displays a set op options to start with, including a useful set of links about color theory. The left sidebar contains the <strong>color chooser</strong> and the right sidebar contains the <strong>color palette</strong>, where we are able to save the colors we choose. At bottom right there is a <strong>color inspector</strong>, displaying info about the color currently under the mouse cursor in any of the application tools.</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_2.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Main window" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb.png" width="612" height="484" /></a> </p>
<p>The largest toolbar at top of the window contains a set of buttons to quickly access all tools, such as the color wheel, a color variations tool, and so on.</p>
<h3>The Color Wheel</h3>
<p>The color wheel is used to select a color harmony. But first a base color should be chosen. ColorImpact provides three different tools to select a color: a wheel, a rectangle and a web safe palette. </p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_30.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="The color wheel" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_12.png" width="196" height="221" /></a>&#160; <a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_32.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="The color rectangle" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_13.png" width="198" height="159" /></a>&#160; <a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_34.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="The web safe palette" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_14.png" width="200" height="169" /></a> </p>
<p>The one I like more is the <strong>interactive color wheel</strong>: by simply clicking the small circle and dragging around the wheel we can select a select a color, and by moving along the radius we can choose a different graduation. During the process of color selection, the color wheel displays the chosen color along with the harmonic colors. Once we&#8217;re satisfied with our base color, we can choose a color harmony schema selecting from a list available at the bottom center.</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_42.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Color Harmonies" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_18.png" width="354" height="196" /></a> </p>
<p>If, for instance, we choose the Square color harmony, we&#8217;ll see the four equally spaced colors in the color wheel highlighted.</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image311.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Color Harmonies tool" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image311_thumb.png" width="542" height="484" /></a> </p>
<p>Colors displayed in the wheel, as well as in any of the tools described below, can be saved in the <strong>color palette </strong>toolbox docked at the right side of the main window, either by double clicking a color on the tool currently in use or dragging a color and dropping into the palette . We have the option of creating multiple palettes, if we need to organize colors in different sets.</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_44.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Color palette" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_19.png" width="174" height="244" /></a> </p>
<h3>Other tools</h3>
<p>ColorImpact provides not just a color wheel and the ability to choose a color harmony schema, but several other useful tools which greatly helps in the process of selecting colors and variations.</p>
<p>The <strong>Advanced Color Wheel </strong>displays a color wheel similar to the one displayed in the Color Harmonies tool, but in addition it provides different hues in inner circles of the wheel. It&#8217;s possible to configure the wheel to display variations from dark to light and vice versa, and from current hues to either darker or lighter variations, more or less saturated, cooler and warmer.</p>
<h3></h3>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image91.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Advanced Color Wheel tool" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image91_thumb.png" width="542" height="484" /></a> </p>
<p>The <strong>Color Formulae</strong> provides a list of colors based on a predefined formula selectable from a list of 30 in the drop down list at bottom of the tool page. For each formula a brief description helps us figuring out what&#8217;s the relation among colors displayed by the tool. Examples of formulas are different hues variations, monochromatic variations, geometrical variations (such as square, rectangle), complementary, and so on.</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image121.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Color Formulae tool" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image121_thumb.png" width="542" height="484" /></a> </p>
<p>Using the <strong>Color Variations</strong> tool we are able to display different color variations, such as darker and lighter, from dark to light and vice versa, more or less saturated, and other combinations.</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image15.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Color Variations tool" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image15_thumb.png" width="642" height="484" /></a> </p>
<p>The <strong>Color Blender,</strong> as it name implies, provides a list of variations of a color blending into another. Starting and ending colors can be chosen by either using the wheel tool (or any of the color picker tools) or by dragging a color from the palette and dropping into one of the ends</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image1811.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Color Blender tool" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image1811_thumb.png" width="642" height="484" /></a> </p>
<p>The last tool is the <strong>Test Pattern</strong>, an undoubtedly useful way of previewing our color palettes and see how colors look when mixed together. There are several test patterns our colors can be tested with, and probably the most interesting to web designers is the <em>Web Page</em> pattern, available in 2 different variations.</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image211.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Web test pattern" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image211_thumb.png" width="612" height="484" /></a> </p>
<p>Using the Test Pattern tool we are able to drag colors from the palette and drop into any of the web page elements. Once we have applied our colors, we can see how our color schema looks like. There are several other test patterns, such as Fashion (displayed below), type designs, shapes and circles.</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image1%5B1%5D.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Fashion test pattern" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image1%5B1%5D_thumb.png" width="612" height="484" /></a> </p>
<p>One of the coolest things about test patterns is that we can create our own, using Flash MX. On the website there is a brief tutorial describing how to create a custom test pattern and adding it to the list of test patterns.</p>
<h2>Import and Export</h2>
<p>I can&#8217;s say that a tool like ColorImpact is useless without import and export features, because I&#8217;d still benefit from using it even manually copying color values. But having such features is a plus (other than a must for most people). Although import is limited to XML and <a title="Color Schemer" href="http://www.colorschemer.com/" target="_blank">Color Schemer</a> (a similar tool for choosing color schemes), ColorImpact is able to export into any of the following formats:</p>
<ul>
<li>Image containing the list of colors along with their hexadecimal values (gif, bmp, jpg, png, windows metafile and enhanced metafile) </li>
<li>Text file, listing all color names and values </li>
<li>HTML Spec Sheet, an html page displaying colors and color values </li>
<li>CSS </li>
<li>ACT Color Table </li>
<li>Paint Shop Pro palette </li>
<li>Photoshop color palette </li>
<li>Illustrator color palette </li>
<li>Freehand ACF palette</li>
</ul>
<h2></h2>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image19.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image19_thumb.png" width="470" height="484" /></a></p>
<p>&#160;<a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image16.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image16_thumb.png" width="644" height="475" /></a></p>
<h2>Additional tools</h2>
<p>Other than the important tools described so far, there are some other minor features making life easier when selecting colors. With the <strong>eye dropper tool</strong> we can select a color from any point of the desktop or any open window, with the additional ability to get either the exact color or an average of its surrounding area</p>
<p>&#160;<a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_36.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_15.png" width="244" height="196" /></a></p>
<p>With the <strong>color blindness simulation</strong> we can simulate how our colors set will be seen by color blindness people.</p>
<p><a href="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_48.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://www.developer-corner.com/Portals/3/digmeta/1/WindowsLiveWriter/Choosingawebcolorscheme_7BC6/image_thumb_21.png" width="244" height="175" /></a> </p>
<p>The <strong>random color </strong>tool simply generates a random color.</p>
<h2>Conclusions</h2>
<p>As mentioned earlier, once I realized that there are tools specifically targeted to simplify color schemes selection, I have tried several tools. In the process of selecting the most appropriate tool I took into account several aspects, such as user friendliness, number of features, exporting capabilities. The tool at the 2nd place of my personal favorite list is Color Schemer, which I didn&#8217;t like for just one thing, very important to me: it runs on a fixed sized window, too small in my opinion, also considering that I&#8217;m used to work with high resolution monitors, such as my 15,4&quot; 1920&#215;1200 laptop display.</p>
<p>ColorImpact implements all the features required to easily and quickly choose web color schemes, also providing unique features I haven&#8217;t seen in other applications. So, I can&#8217;t do anything else than suggesting to whoever reads this blog post to give it a try &#8211; you&#8217;ll like it. A 15 days trial version can be downloaded at the following address:</p>
<p><a title="Color Impact Trial" href="http://www.tigercolor.com/Download/Default.htm">http://www.tigercolor.com/Download/Default.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/tech-area/choosing-a-web-color-scheme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data integrity check using hashing</title>
		<link>http://www.developer-corner.com/development/dotnet/data-integrity-check-using-hashing/</link>
		<comments>http://www.developer-corner.com/development/dotnet/data-integrity-check-using-hashing/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 07:32:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[World.NET]]></category>
		<category><![CDATA[hashing signature c#]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/development/dotnet/data-integrity-check-using-hashing/</guid>
		<description><![CDATA[When data are moved across a network the recipient might require a verification to ensure that data have not been modified after send. For example, in a client/server scenario where a client application sends some updates to a remote database via a web service, the web service might need to verify that data have not been modified while travelling across the network, either due to corruption or because somebody changed them. A simple way to implement such kind of verification is utilizing hashing.]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>When data is moved across a network, the recipient might require a verification to ensure that data has not been modified after send. For example, in a client/server scenario where a client application sends some updates to a remote database via a web service, the web service might need to verify whether the data has not been modified while travelling across the network, either due to corruption or because somebody changed them. A simple way to implement such kind of verification is utilizing <strong>hashing</strong>.</p>
<h2>How Hashing works</h2>
<p>The idea behind hashing is to generate a (ideally) <strong>unique </strong>and <strong>non–reversible code</strong> generated from the data being sent. <em>Unique </em>means that the codes generated for 2 different sets of data must differ each other, even if each set of data has a size of 1 Mb and they differ by 1 byte only. <em>Non-reversible </em>means that the hash code cannot be used to recreate the original data.</p>
<p>For the purpose of signing data to check for modification, the non-reversibility feature is unnecessary, as the hash code travels with the data, but there are other cases where it is undoubtedly useful. For example, one of the easiest way to prevent passwords from being stored in a database is to store a hash code rather than the password. This way when a user is authenticating the password is used to generate an hash key, which is compared to the hash key stored in the database (previously generated when the user account has been created, or the last time the user has changed his password) – if&#160; they match, authentication succeeds. The drawback of this method is that a “recall password” feature cannot be implemented, as the password is not stored anywhere, and the non reversibility property of the hash code prevents it from being used to recreate the original data – in such case a “reset password” feature is more appropriate.</p>
<h2>Hashing and Salting</h2>
<p>Using the model described above data is protected against corruption but not against changes. In fact, whereas a corruption is immediately detected once the recipient verifies that the <a class="zem_slink" title="Hash function" href="http://en.wikipedia.org/wiki/Hash_function" rel="wikipedia">hash codes</a> don’t match, an hacker attempting to modify the data simply has to create a new hash code. Since this code is sent with the data, and since the hashing algorithm is deterministic, whoever wants to modify the data has all ingredients to do so, with no risk of being detected.</p>
<p>So hashing is not enough to guarantee data integrity. One common practice is to use a random or predefined string, which is appended to the data before calculating the hash code. This additional string is known as <strong><a class="zem_slink" title="Salt (cryptography)" href="http://en.wikipedia.org/wiki/Salt_%28cryptography%29" rel="wikipedia">salt</a></strong>. If the salt is known by sender and recipient only, an hacker has no way to generate an hash code that won’t be immediately detected by the recipient during hash verification. </p>
<p>In this scenario the salt can be thought as a private key shared between sender and recipient.</p>
<p>For improved security, it’s better if the salt is not 100% static – for example, a dynamic string depending from the date and/or time can be mixed to the static salt in order to generate a dynamic salt, harder for an hacker to guess. For this method to work both sender and recipient must generate the same salt in a wide enough time window. For example, supposing that sender and recipient have their clocks synchronized, if the salt is composed by current hour and minute, the widest time window is 60 seconds – but the recipient could generate a different salt just 1 second after the sender generated the salt code, if this occurs, for example, at 10:20:59. In this case the sender use 10:20 to generate the salt – if the recipient receives the message at least 1 second later, it will use 10:21 to generate the salt. And this obviously leads to a completely different hash code.</p>
<h2>Implementing a data integrity check</h2>
<p>There are several algorithms that can be use to generate hash codes. One of them is <a class="zem_slink" title="MD5" href="http://en.wikipedia.org/wiki/MD5" rel="wikipedia">MD5</a>, implementable as follows:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:32b9c5de-4f6b-4225-9f63-15e6723ba9d8" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">using System;
using System.Security.Cryptography;
using System.Text;

namespace Hash
{
	public class HashGenerator
	{
		public static string GenerateMd5Hash(string salt, string data)
		{
			byte[] buffer;
			byte[] binaryHash;
			string stringHash;
			MD5 md5;

			md5 = MD5.Create();

			// Combine salt + data and convert to array of bytes
			buffer = Encoding.Unicode.GetBytes(salt + data);

			// Create the hash code from salt + data
			binaryHash = md5.ComputeHash(buffer);

			// The hash code is in binary format - convert
			// it in readable string
			stringHash = Convert.ToBase64String(binaryHash);

			return stringHash;
		}
	}
}</pre>
</div>
<p>The code is pretty simple: salt + data are combined together and converted to array of bytes, then the ComputeHash method of the MD5 instance creates the hash code given the array of bytes. Last, since the hash generated by ComputeHash is in binary format, it is converted to string and returned. To test this code we can create a simple console application like the following one:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:26f29fe8-18a1-457b-8373-67f830b89b57" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">using System;
using Hash;

namespace HashSample
{
	public class Program
	{
		static void Main(string[] args)
		{
			string test;
			string hash;
			string salt;

			test = "This is a sample data";
			salt = "FTSA74D71KSAP";

			hash = HashGenerator.GenerateMd5Hash(salt, test);

			Console.Out.WriteLine(
				"The hash code for string '{0}' and salt '{1}' is:\n\t{2}",
				test, salt, hash
			);

			Console.In.Read();
		}
	}
}</pre>
</div>
<p>The output produced by this application is the following:</p>
<p><code>The hash code for string 'This is a sample data' and salt 'FTSA74D71KSAP' is:<br />
    <br />s2gxEi9C3QSRGFy+cZheWA== </code></p>
<p>To prove how the hash code changes by simply changing 1 byte in the original data, let’s see what happens if we slightly change the test string to “This is <strong>b</strong> sample data”:</p>
<p><code>The hash code for string 'This is b sample data' and salt 'FTSA74D71KSAP' is:<br />
    <br />FJr7RUcSYJMJBdfCg6DCXQ== </code></p>
<p>We can see that these 2 hashes are completely different.</p>
<h2>IHashable interface</h2>
<p>If we need to generate an hash code on instances of a class, why don’t we define a proper interface? This way we can just implement the interface and write a single function to generate the hash code. The interface name is, of course, IHashable:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:5f63b33d-07c5-48d1-af5d-e8e370f634aa" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public interface IHashable
{
    string GetHashableRepresentation();
    string GenerateSalt();
}</pre>
</div>
<p>and consists of 2 methods: GetHashableRepresentation and GenerateSalt. The latter should be implemented in order to generate a proper salt code, whereas the former should return a representation of the class instance in a string format suitable for hashing &#8211; for example, a simple string concatenation of all data members.</p>
<p>As I mentioned earlier, there are several algorithms usable for hashing. Following a comprehensive implementation of the hash generation, which allows the caller to choose which algorithm to use:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:88f4a685-cc29-4e26-b4fb-b647a5aa7d01" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public enum HashingAlgorithm
{
    Md5,
    Sha1,
    Sha256,
    Sha384,
    Sha512,
    RipeMd160
}

public static string GenerateHash(HashingAlgorithm alg, IHashable hashable)
{
    HashAlgorithm algorithm;

    algorithm = CreateHashAlgorithm(alg);

    byte[] buffer;
    byte[] binaryHash;
    string stringHash;

    // Combine salt + data and convert to array of bytes
    buffer = Encoding.Unicode.GetBytes(hashable.GetHashableRepresentation() + hashable.GenerateSalt());

    // Create the hash code from salt + data
    binaryHash = algorithm.ComputeHash(buffer);

    // The hash code is in binary format - convert
    // it in readable string
    stringHash = Convert.ToBase64String(binaryHash);

    return stringHash;
}

private static HashAlgorithm CreateHashAlgorithm(HashingAlgorithm alg)
{
    HashAlgorithm algorithm;

    switch (alg)
    {
        default:
        case HashingAlgorithm.Md5:
            algorithm = MD5.Create();
            break;

        case HashingAlgorithm.Sha1:
            algorithm = SHA1.Create();
            break;

        case HashingAlgorithm.Sha256:
            algorithm = SHA256.Create();
            break;

        case HashingAlgorithm.Sha384:
            algorithm = SHA384.Create();
            break;

        case HashingAlgorithm.Sha512:
            algorithm = SHA512.Create();
            break;

        case HashingAlgorithm.RipeMd160:
            algorithm = RIPEMD160.Create();
            break;
    }

    return algorithm;
}</pre>
</div>
<p>The GenerateHash method requires 2 parameters: the algorithm to use and an instance of IHashable. In return, the method provides an hash code generated using the specified algorithm. </p>
<p>Last thing to mention, a helpful method to compare an hash code with an IHashable instance – its implementation is really very simple:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:57bb713a-396b-41e8-91d4-c558b5a9f9da" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public static bool CompareHashes(HashingAlgorithm alg, string hash, IHashable hashable)
{
    return GenerateHash(alg, hashable).Equals(hash);
}</pre>
</div>
<h2>Digital signature</h2>
<p>When used alone, hashing is good but it’s not the best. There are better ways, out of the scope of this article – but I want to spend a few words about them.</p>
<p>The safest and more secure way to sign data is using <a class="zem_slink" title="Digital signature" href="http://en.wikipedia.org/wiki/Digital_signature" rel="wikipedia">digital signature</a>, which make use of asymmetric cryptography (also known as <a class="zem_slink" title="Public-key cryptography" href="http://en.wikipedia.org/wiki/Public-key_cryptography" rel="wikipedia">public key cryptography</a>). The idea is to encrypt the hash code so that it cannot be modified.</p>
<p>In cryptography a key is used to encrypt and decrypt data – it’s not an algorithm, but a secret data used for encryption: using a different key different encrypted data is generated. A (very simple) example of key is the salt we’ve seen earlier: changing the salt will produce a different hash code.</p>
<p>Keys are usually used to encrypt and decrypt data. In symmetric cryptography the same key is used to encrypt and decrypt data. This is the biggest limitation, as the key must be owned by both parties involved in the encryption and decryption process, or sent along with the encrypted data if the recipient doesn’t have the key. </p>
<p>In public key cryptography a key is composed by a public key and a private key. The private key, as the name implies, is private and should never be sent to anybody. On the other hand, the public key can be published and made available to anybody. The key owner uses his private key to encrypt data – anybody can decrypt the data using the public key, but the cool feature is that the public key can be used to decrypt data encrypted by the corresponding private key only. This means that who is decrypting is sure that data has been encrypted by the owner of the private key only. Keys can also be used in the opposite way: data encrypted with the public key can only be decrypted by the corresponding private key. This way whoever encrypts data using the public key is sure that data will be available to the owner of the corresponding private key only.</p>
<p>In our hashing problem, if the sender encrypts the hash code using his private key, the recipient is able to detect any unauthorized data modification:</p>
<ul>
<li>if the data gets corrupted or changed, the hash code calculated from the data won’t match with the encrypted hash code provided with the data </li>
<li>if the encrypted hash code provided with the data is modified, it won’t match with the hash code calculated from the data </li>
</ul>
<p>&#160;</p>
<div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/de66927d-6964-4cc6-b3bf-67f49fa55c44/"><img class="zemanta-pixie-img" alt="Reblog this post [with Zemanta]" src="http://img.zemanta.com/reblog_e.png?x-id=de66927d-6964-4cc6-b3bf-67f49fa55c44" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/development/dotnet/data-integrity-check-using-hashing/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Mark a C# class data member as readonly when it&#8217;s read only</title>
		<link>http://www.developer-corner.com/development/dotnet/mark-a-c-class-data-member-as-readonly-when-its-read-only/</link>
		<comments>http://www.developer-corner.com/development/dotnet/mark-a-c-class-data-member-as-readonly-when-its-read-only/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 07:22:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[World.NET]]></category>
		<category><![CDATA[c# readonly]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/development/dotnet/mark-a-c-class-data-member-as-readonly-when-its-read-only/</guid>
		<description><![CDATA[2009.01.30 - Updated in order to clarify about immutability.

The readonly modifier is used to declare an instance-specific constant data member which can be initialized in the class constructor and is not limited to compiler-time constants only.]]></description>
			<content:encoded><![CDATA[<p>The <strong>readonly </strong>modifier is used to declare a constant data member in a class, but providing more flexibility than using the <strong>const </strong>modifier. The const modifier implicitly defines the data member as static, and must be initialized along with its declaration, as follows:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:3e27b695-ee64-4b62-bc3b-73a3ac8b4a84" class="wlWriterEditableSmartContent">
<pre class="brush: c#;wrap-lines:false;">public const int myConst = 5;</pre>
</div>
<p>If the const is not initialized along with the declaration, the compiler will generate an error.</p>
<p>Moreover, a const data member must be initialized with a compile-time constant – in other words there is no way to initialize a constant using a runtime value. For instance, the following code doesn’t compile:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:46ee27e9-f7fc-48fc-b8d3-bd359291f18b" class="wlWriterEditableSmartContent">
<pre class="brush: c#;wrap-lines:false;">public class MyClass
{
	public static string nonConstValue = "This is a variable initialized at runtime";
	public const string constValue = nonConstValue;		// Compilation error
	...
}</pre>
</div>
<p>as the compiler will inform that “The expression being assigned to &#8216;MyClass.constValue&#8217; must be constant”.</p>
<p>The advantage of defining a data member as <strong>const </strong>is that it cannot be changed – the drawback being the inability to initialize the field in a different place other than the declaration.</p>
<p>On the other hands, the <strong>readonly</strong> modifier extends the const modifier by allowing the data member to be initialized <em>in any class constructor</em>. This allows a data member to be initialized when a class is being instantiated, preventing it from being modified in any other class method – in other words, once the const data member is initialized it never changes during the class instance lifetime. As opposed to the const modifier, the readonly modifier creates an instance-specific data member, so each class instance will have its own readonly data member instances. This doesn’t mean that a readonly data member cannot be static – simply it must explicitly be declared as such.</p>
<p>All the following declarations and initializations are valid:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:673ed0a4-6f47-4894-936e-f11f3a9564cb" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public class MyClass
{
	public readonly int _myIntField = 5;	// Allowed
	public readonly string _myStringField;	// Allowed

	public MyClass()
	{
		_myIntField = 8;									// Allowed
		_myStringField = "Initialized in the constructor";	// Allowed
	}

	public static void Main()
	{
		MyClass myClass;

		myClass = new MyClass();

		System.Console.Out.WriteLine(string.Format("myIntField = {0}", myClass._myIntField));
		System.Console.Out.WriteLine(string.Format("myStringField = {0}", myClass._myStringField));
	}
}</pre>
</div>
<p>The member declared at line 4 is initialized in the constructor with a string constant, whereas the int member declared at line 3 is initialized both in the declaration and in the constructor. In this case, the constructor initialization takes precedence, as it is executed after the data member instantiation.</p>
<p>The following case instead is not valid</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:f14a6803-53f0-4f13-b58f-3a6c2dedc8c2" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public class MyClass
{
	public readonly string _myStringField;	// Allowed

	public MyClass()
	{
		Init();
	}

	private void Init()
	{
		_myStringField = "Cannot be initialized here";		// Compilation error
	}

	...
}</pre>
</div>
<p>That’s because the readonly member is initialized in a class member which is not a constructor, even if this method is called from the constructor. The reason why this is not allowed is that the Init() method can be called from anywhere within the class, or even outside if it is protected, internal or public rather than private.</p>
<p>Another advantage of the readonly modifier is that it can be initialized with a runtime value or an expression evaluated at runtime, for instance:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:fa127ac5-f333-4aed-ae02-a0c974819e9d" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public class MyClass
{
	public readonly int  _myIntField;	// Allowed

	public MyClass(int runtimeValue)
	{
		_myIntField = 10 * runtimeValue;
	}

	public static void Main()
	{
		MyClass myClass;

		myClass = new MyClass(5);

		System.Console.Out.WriteLine(string.Format("myIntField = {0}", myClass._myIntField));
	}
}</pre>
</div>
<p>As we can expect, the _myIntField readonly data member will be initialized to 10 * 5 = 50.</p>
<p>Readonly data members are not limited to basic data types – it can be used for class instances. For example, when writing a database accessor class we might want to provide a database connection:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:25468d05-105c-4c40-9666-35310b4b2249" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public class MyDatabaseAccessor
{
	private readonly SqlConnection _connection;

	public MyDatabaseAccessor (SqlConnection connection)
	{
		_connection = connection;
		...
	}

	...

}

public class MyApp
{
	public static void Main()
	{
		SqlConnection connection = new SqlConnection();

		// Initialize the connection
		...

		MyDatabaseAccessor myAccessor = new MyDatabaseAccessor(connection);

		// Do something
		...
	}
}</pre>
</div>
<p>The above code would work without declaring the _connection data member as readonly – but in such case the connection can be changed anywhere in the class.</p>
<p>It’s important to keep in mind that when a readonly data member is of a reference type (i.e. instance of a class and not either a struct or a base data type) the reference is constant, but the instance it points to is not. So the internal status of a readonly instance can change and can be changed, as proven by the following sample:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c666dded-1e9f-4144-976a-0d342936cc04" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">// Class with a data member
public class MyClassType
{
	private string _internalStatus;

	public string InternalStatus {
		get {return _internalStatus;}
		set {_internalStatus = value;}
	}
}

// Class with a readonly data member
public class MyClassWithReadonlyMember
{
	private readonly MyClassType _readonlyInstance;

	public MyClassWithReadonlyMember(string value)
	{
		_readonlyInstance = new MyClassType();
		_readonlyInstance.InternalStatus = value;
	}

	public void SetStatus(string message)
	{
		_readonlyInstance.InternalStatus = message;
	}

	public void OutputStatus()
	{
		System.Console.Out.WriteLine(string.Format(
				@"Internal status = '{0}'", _readonlyInstance.InternalStatus));
	}
}

public class MyApp
{
	public static void Main()
	{
		MyClassWithReadonlyMember classInstance;

		// Create an instance of MyClassWithReadOnlyMember class
		// The instance of MyClassType is initialized to the default
		// value provided in the constructor
		classInstance = new MyClassWithReadonlyMember("Initial value");
		classInstance.OutputStatus();

		// The internal status of the readonly data member of
		// MyClassWithReadonlyMember is changed
		classInstance.SetStatus("New Value");
		classInstance.OutputStatus();
	}
}</pre>
</div>
<p>If this code is compiled and run. it will generate the following output:</p>
<blockquote>
<p>Internal status = &#8216;Initial value&#8217;<br />
    <br />Internal status = &#8216;New Value&#8217;</p>
</blockquote>
<p>&#160;</p>
<h2>2009.01.30 Addendum</h2>
<p>Thanks to what Chris Marisic highlighted in his comments below, I need to clarify a few points to prevent some misleading assumptions.</p>
<p><strong>#1</strong> &#8211; readonly members can be modified using reflection. The readonly modifier is a compiler directive, so any attempt to modify a readonly data member is detected during compilation. A consequence is that using reflection it&#8217;s possible to modify a readonly data member</p>
<p><strong>#2 &#8211; </strong>I wrote above that the const modifier &quot;<em>allows a data member to be initialized when a class is being instantiated, preventing it from being modified in any other class method</em>&quot;. This statement doesn&#8217;t mean that the data member is immutable, at least not always. .NET supports two kinds of data types: <strong>value types</strong> and <strong>reference types</strong>.:</p>
<ul>
<li>value types are allocated on the thread&#8217;s stack and they hold the actual value </li>
<li>reference types are allocated on the thread&#8217;s stack and they hold a pointer to an object allocated in the managed heap </li>
</ul>
<p>In both cases variables are allocated on the thread&#8217;s stack, the difference being that a value type holds the actual value (for example, an integer, a struct), whereas the reference type holds a pointer to the memory area where the actual value is stored (for example, an instance of a StringBuilder class). </p>
<p>When a value type is declared as readonly, its value is immutable, meaning that once assigned it cannot be modified outside constructors.</p>
<p>When a reference type is declared as readonly, the pointer is immutable, but not the object it points to. This means that:</p>
<ul>
<li>a reference type data member can be initialized in order to point to an instance of a class, but once this is done it&#8217;s not possible to make it point to another instance of a class outside of constructors </li>
<li>the readonly modifier has no effect on the object the readonly data member points to. </li>
</ul>
<p>Maybe a real example helps to better understand the difference. Let&#8217;s create a simple class and a simple struct. They have one int data member only.</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:1ad037a3-6cce-422e-8bf0-5e53130eb139" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public class MyClass
{
	public int IntField;
}

public struct MyStruct
{
	public int IntField;
}</pre>
</div>
<p>Now let&#8217;s use them in a test class:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:45a3088e-d7d8-4481-b58b-7b67814ef743" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public class MyTestClass
{
	private readonly MyClass _myClass;
	private readonly MyStruct _myStruct;

	public MyTestClass()
	{
		_myClass = new MyClass();
		_myClass.IntField = 4;

		_myStruct.IntField = 5;
	}
}</pre>
</div>
<p>The _myClass data member is a reference type, so it must be initialized by allocating a new instance of MyClass and assigning its pointer, as seen at line 8. On the other hand, the _myStruct data member is a value type, meaning that it is already an instance of MyStruct. Initialization of their respective fields are done at lines 9 and 11.</p>
<p>Let&#8217;s add a method to the MyTestClass class.</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:e40ced14-5a4e-49f3-ab97-cc6504cf81a2" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public class MyTestClass
{
	private readonly MyClass _myClass;
	private readonly MyStruct _myStruct;

	public MyTestClass()
	{
		_myClass = new MyClass();
		_myClass.IntField = 4;

		_myStruct.IntField = 5;
	}

	public void TestReadonly()
	{
		_myClass.IntField = 7;		// Valid statement
		_myStruct.IntField = 10;	// Error: _myStruct is readonly
		_myClass = null;			// Error: _myClass is readonly
	}
}</pre>
</div>
<p>If we try to compile this code, we get 2 errors:</p>
<blockquote>
<p>MyTest.cs(26,3): error CS1648: Members of readonly field &#8216;MyTestClass._myStruct&#8217;<br />
    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; cannot be modified (except in a constructor or a variable initializer)</p>
<p>
    <br />MyTest.cs(27,3): error CS0191: A readonly field cannot be assigned to (except in </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; a constructor or a variable initializer)</p>
</blockquote>
<p><font face="Lucida Console"></font></p>
<p>MyStruct is a struct, hence a value type; _myStruct is immutable since declared as readonly, so any of its data members cannot be modified outside of a constructor.</p>
<p>MyClass is a class, hence a reference type; _myClass is immutable since declared as readonly, so it cannot be modified in order to point to another instance of a class (or to null) outside of a constructor.</p>
<p>&#160;</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c73a0cda-aa7b-4302-a3b5-bdc88694868b" class="wlWriterSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/C%23" rel="tag">C#</a>,<a href="http://del.icio.us/popular/csharp" rel="tag">csharp</a>,<a href="http://del.icio.us/popular/readonly" rel="tag">readonly</a>,<a href="http://del.icio.us/popular/const" rel="tag">const</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/development/dotnet/mark-a-c-class-data-member-as-readonly-when-its-read-only/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DataGridView: how to bind nested objects</title>
		<link>http://www.developer-corner.com/development/dotnet/datagridview-how-to-bind-nested-objects/</link>
		<comments>http://www.developer-corner.com/development/dotnet/datagridview-how-to-bind-nested-objects/#comments</comments>
		<pubDate>Thu, 19 Jul 2007 06:30:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[World.NET]]></category>
		<category><![CDATA[c# WinForms DataGridView]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/development/dotnet/datagridview-how-to-bind-nested-objects/</guid>
		<description><![CDATA[A DataGridView can be bound to a collection of objects to display any of its base data type (i.e. string, int, and so on) properties. But what happens when the class exposes other objects which are not base data type?]]></description>
			<content:encoded><![CDATA[<h3>The Problem</h3>
<p>A DataGridView can be bound to a collection of objects to display any of its base data type (i.e. string, int, and so on) properties. For example, a collection of instances of the following class:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c1c0347a-7258-47da-9f4a-65a74fcdb426" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public class Customer
{
  public string FirstName { get; set;}
  public string LastName { get; set;}
  public string Street { get; set;}
  public string PostalCode { get; set;}
  public string City { get; set;}
} </pre>
</div>
<p>can be used to display any of the <span class="inline-code">Customer</span> class properties in the DataGridView.</p>
<p><img alt="" src="http://www.developer-corner.com/Portals/3/articles/28/nested_prop_1.JPG" /></p>
<p>But what happens when the class exposes other objects which are not base data type? If an <span class="inline-code">Address</span> class is created and used as a property of the <span class="inline-code">Customer</span> class:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:6255cc4d-acc8-45ff-a769-54a86e92cd2e" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public class Address
{
  public string Street { get; set;}
  public string PostalCode { get; set;}
  public string City { get; set;}
}

public class Customer
{
  public string FirstName { get; set;}
  public string LastName { get; set;}
  public Address Address { get; set;}
}</pre>
</div>
<p>a DataGridView bound to a collection of <span class="inline-code">Customer</span> instances is not able to display any of the <span class="inline-code">Address</span> properties. In such cases the displayed cells are empty</p>
<p><img alt="" src="http://www.developer-corner.com/Portals/3/articles/28/nested_prop_2.JPG" /></p>
<h3>The Solution</h3>
<p>In order to enable the DataGridView to display properties exposed by class members, some custom development is required. The first step is to implement the DataGridView&#8217;s <span class="inline-code">CellFormatting</span> event handler</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:ae5585ee-8057-4185-bceb-d30b6128a14e" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">private void gridCustomers_CellFormatting(
  object sender,
  DataGridViewCellFormattingEventArgs e)
{
  ...
}</pre>
</div>
<p>The <span class="inline-code">CellFormatting </span>event handler needs to differentiate whether the field to be displayed is one of the base data type or an object exposing its own properties. This is achieved by looking for the dot character <span class="inline-code">&#8216;.&#8217;</span> in the <span class="inline-code">Column</span>&#8216;s <span class="inline-code">DataPropertyName</span> field:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:fe0ab780-1b1d-48bd-b6a2-d3cb68e2109c" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">private void gridCustomers_CellFormatting(
  object sender,
  DataGridViewCellFormattingEventArgs e)
{
  if ((gridCustomers.Rows[e.RowIndex].DataBoundItem != null) &amp;&amp;
      (gridCustomers.Columns[e.ColumnIndex].DataPropertyName.Contains(".")))
  {
    ...
  }
}</pre>
</div>
<p>If the DataPropertyName field doesn&#8217;t contain a dot character, then the actual value of the base data type property must be displayed &#8211; in this case no action is required, since it is already filled in <span class="inline-code">e.Value</span>.</p>
<p>On the other hand, if the <span class="inline-code">DataPropertyName</span> field contains one or more dot characters, then it points to a property exposed by one of the bound class properties. For example, Address.Street contains the dot character, and it points to the Street property of the Address property inside a Customer&#8217;s instance.</p>
<p>To handle this cases,&#160; a recursive function <span class="inline-code">BindProperty</span> is used:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:460ed441-f486-485c-aa5a-c7e420a7670e" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">private void gridCustomers_CellFormatting(
  object sender,
  DataGridViewCellFormattingEventArgs e)
{
  if ((gridCustomers.Rows[e.RowIndex].DataBoundItem != null) &amp;&amp;
      (gridCustomers.Columns[e.ColumnIndex].DataPropertyName.Contains(".")))
  {
	e.Value = BindProperty(
                gridCustomers.Rows[e.RowIndex].DataBoundItem,
                gridCustomers.Columns[e.ColumnIndex].DataPropertyName
              );
  }
}</pre>
</div>
<p>The <span class="inline-code">BindProperty </span>function resolves the data property name and provides the actual value to be displayed in the grid&#8217;s cell by using reflection and (if required) recursion. Two arguments are passed to the <span class="inline-code">BindProperty</span> function: the class property value (which is an instance of a class, in the above example an instance of the <span class="inline-code">Address</span> class) and the <span class="inline-code">DataPropertyName:</span></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:0057c108-8c67-493f-9301-4920e8445829" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">private string BindProperty(object property, string propertyName)
{
  ...
}</pre>
</div>
<p>The first thing to check is whether the property name contains the dot character &#8211; although this never happen when called directly from the <span class="inline-code">CellFormatting</span> event handler, since the <span class="inline-code">if</span> statement prevent this, it may happen when <span class="inline-code">BindProperty</span> calls itself recursively.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:03a237b9-9742-4c50-abfa-dc6ddea84fdb" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">private string BindProperty(object property, string propertyName)
{
  if (propertyName.Contains("."))
  {
    ...
  }
  else
  {
    ...
  }
}</pre>
</div>
<p>If the property name doesn&#8217;t contain any dot character, then the <span class="inline-code">propertyName</span> variable contains the name of the <span class="inline-code">property</span> object to be displayed in the grid. Reflection is used to read the property value, obtained by retrieving the <span class="inline-code">PropertyInfo</span> from the <span class="inline-code">property</span> variable, and then getting the property value by calling the <span class="inline-code">GetValue()</span> method of the <span class="inline-code">PropertyInfo</span> instance:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:2fadc604-fdad-44b5-9de3-0b8d92d6e9fc" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">private string BindProperty(object property, string propertyName)
{
  string retValue = "";

  if (propertyName.Contains("."))
  {
    ...
  }
  else
  {
    Type propertyType;
    PropertyInfo propertyInfo;

    propertyType = property.GetType();
    propertyInfo = propertyType.GetProperty(propertyName);
    retValue = propertyInfo.GetValue(property, null).ToString();
  }
}</pre>
</div>
<p>This completes the else branch. As for the if branch, it is executed when the property name contains at least one dot character. In this case, still using reflection, the <span class="inline-code">PropertyInfo</span> of the desired property is retrieved, and using recursion, passed to the same <span class="inline-code">BindProperty</span> function.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:6941634d-b231-4f8c-8527-665173de553c" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">private string BindProperty(object property, string propertyName)
{
  string retValue = "";

  if (propertyName.Contains("."))
  {
    PropertyInfo[] arrayProperties;
    string leftPropertyName;

    leftPropertyName = propertyName.Substring(0, propertyName.IndexOf("."));
    arrayProperties = property.GetType().GetProperties();

    foreach (PropertyInfo propertyInfo in arrayProperties)
    {
      if (propertyInfo.Name == leftPropertyName)
      {
        retValue = BindProperty(
          propertyInfo.GetValue(property, null),
          propertyName.Substring(propertyName.IndexOf(".") + 1));
        break;
      }
    }
  }
  else
  {
    Type propertyType;
    PropertyInfo propertyInfo;

    propertyType = property.GetType();
    propertyInfo = propertyType.GetProperty(propertyName);
    retValue = propertyInfo.GetValue(property, null).ToString();
  }

  return retValue;
}</pre>
</div>
<p>The <span class="inline-code">leftPropertyName</span> variable holds the name of the leftmost property, for instance if <span class="inline-code">propertyName</span> is Address.Street, it is filled in with <span class="inline-code">Address</span>. By looping through the array of <span class="inline-code">PropertyInfo</span> of the <span class="inline-code">property</span> object, the <span class="inline-code">PropertyInfo</span> instance of the <span class="inline-code">leftPropertyName</span> property is retrieved. Then, <span class="inline-code">BindProperty</span> is called again, passing the instance of the <span class="inline-code">leftPropertyName</span> property and the right part of <span class="inline-code">propertyName</span> (for instance, for <span class="inline-code">Address.Street</span> the provided property name is <span class="inline-code">Street</span>).</p>
<p>Using the above code, this is the result:</p>
<p><img alt="" src="http://www.developer-corner.com/Portals/3/articles/28/nested_prop_3.JPG" /></p>
<p>The code is available for download <a href="http://www.developer-corner.com/Downloads/tabid/126/Default.aspx">here</a> (registration is required)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/development/dotnet/datagridview-how-to-bind-nested-objects/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Single Sign On across multiple ASP.NET applications</title>
		<link>http://www.developer-corner.com/development/dotnet/single-sign-on-across-multiple-asp-net-applications/</link>
		<comments>http://www.developer-corner.com/development/dotnet/single-sign-on-across-multiple-asp-net-applications/#comments</comments>
		<pubDate>Mon, 02 Oct 2006 06:11:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[World.NET]]></category>
		<category><![CDATA[c# asp.net SSO]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/development/dotnet/single-sign-on-across-multiple-asp-net-applications/</guid>
		<description><![CDATA[The most used authentication type under ASP.NET in a web environment is the Forms Authentication. Sometimes we need multiple applications, each one implementing its own authentication, to share authentication data between other applications, so that if a user logs in one application, he doesn't need to sign in again when accessing the other applications.]]></description>
			<content:encoded><![CDATA[<div class="focus-right">
<h3>Machine Key</h3>
<p> The <span class="inline-code">machineKey</span> element of the web.config file is used to specify keys for encryption and decryption of forms authentication cookies and view state data, and also when dealing with out of process session state.     <br />The default configuration uses auto generated decryption key and validation key, and SHA1 encryption type.     <br />Using the default configuration, different web applications have different decryption and validation key, since they are randomly generated. To force 2 applications to use the same keys, they must be explicitly defined i<span class="style1">n the web.config file</span>     <br />A complete description of the <span class="inline-code">machineKey</span> element is available <a href="http://msdn2.microsoft.com/en-us/library/w8h3skw9.aspx" target="_blank">here</a></div>
<h3>Single Sign On</h3>
<p><span class="highlight">Single Sign On (SSO)</span> is a term used to indicate when a pool of applications need a centralized authentication, so that users login once and access to any application.</p>
<p>Implementing a single sign on is quite simple, and can be done by configuring the applications using the web.config file.</p>
<p>&#160;</p>
<p>A default configuration for forms authentication is defined as follows:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:2304a8b6-5e8c-46d8-95ff-b225ad947e38" class="wlWriterEditableSmartContent">
<pre class="brush: xml;">&lt;configuration&gt;
  ...
  &lt;system.web&gt;
    ...
    &lt;authentication mode="Forms"&gt;
      &lt;forms name=".cookiename"
             loginUrl="~/Login.aspx"
             timeout="30"
             path="/" /&gt;
    &lt;/authentication&gt;
    ...
  &lt;/system.web&gt;
  ...
&lt;/configuration&gt; </pre>
</div>
<p></p>
<div class="focus-right">
<h3>Form Authentication</h3>
<p>Forms Authentication uses an authentication ticket stored in either a cookie or embedded i<span class="style1">n the url.<br />
    <br />When used in cookie mode, the c</span>ookie contains authentication data, encrypted so that data can be read by the application who has created the cookie. </p>
<p>Cookies are associated to 2nd level domains (example.com), and can be accessed from any 3rd level domain (www.example.com, test.example.com, and so on).</div>
<p>where <code class="inline-code">.cookiename, by default, is</code> <code class="inline-code">.ASPXFORMSAUTH</code>.</p>
<p>In order for authentication data to be recognized across multiple applications, each application must be configured to use the same values for cookie name, protection and path attributes. But this isn&#8217;t enough &#8211; in fact, they must also have the same machine key values (see the side box for more info about the <span class="inline-code">machineKey</span> element). These information are used to encrypt the forms authentication cookie, as mentioned in the &quot;Forms Authentication&quot; side box.</p>
<p>Below a sample web.config excerpt which must be added to each application we want single sign on enabled. In this sample, the validationKey and encryptionKey attributes must be replaced with unique values you have to generate for your applications pool.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:ad612840-60af-4c4f-a849-cc7177cf3731" class="wlWriterEditableSmartContent">
<pre class="brush: xml;">&lt;configuration&gt;
  ...
  &lt;system.web&gt;
    ...
    &lt;authentication mode="Forms"&gt;
      &lt;forms name=".cookiename"
             loginUrl="~/Login.aspx"
             timeout="30"
             path="/"
      /&gt;
    &lt;/authentication&gt;
    ...
    &lt;machineKey
       validationKey=
         "F9D1A2D3E1D3E2F7B3D9F90FF3965ABDAC304902"
      encryptionKey=
         "F9D1A2D3E1D3E2F7B3D9F90FF3965ABDAC304902F8D923AC"
      validation="SHA1"
    /&gt;
    ...
  &lt;/system.web&gt;
  ...
&lt;/configuration&gt; </pre>
</div>
<h3>Second and third level domains</h3>
<p>If the cooperating applications are installed under the same 2nd and 3rd level domain, but on different virtual folders, then no additional code is required. </p>
<p>If applications are installed on different second level domains (www.domain1.com and www.domain2.com), the SSO method described in this article won&#8217;t work, since cookies cannot be read by applications under different second level domains. For example, if application A in domain1.com issues a cookie, the cookie may be read by A itself and any application hosted under <a href="http://www.domain1.com">www.domain1.com</a> and any other 3rd level domain (test.domain1.com, beta.domain1.com, and so on). Application B in domain2.com isn&#8217;t able to read the cookie, since it is hosted under a different second level domain.</p>
<p>If cooperating applications are installed on different third level domains, then we need to add some code in order to make SSO work. The code simply has to add the domain name to the authentication cookie, as outlined below</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:87534bb3-4ab2-46a7-a33a-368a3eb6c5f8" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">protected void Login (string strUserName, ...)
{
  ...
  System.Web.HttpCookie cookie; 

  cookie = FormsAuthentication.GetAuthCookie(strUserName, False);
  cookie.Domain = "domain1.com";
  cookie.Expires = DateTime.Now.AddDays (-1);
  Response.AppendCookie (cookie);
  ...
} </pre>
</div>
<h3>Cookie Expiration</h3>
<p>If different applications set different cookie expirations, the actual expiration value is the one set by the application which issued it. So if application A is configured to set an expiration of 1 hour and application B 2 hours, and the user signs in using application B, then the cookie expiration is set to 2 hours.</p>
<h3>Logging out</h3>
<p>Usually, in order to log out a user, a call to the <span class="inline-code">Authentication.SignOut()</span> method is used &#8211; this isn&#8217;t enough when using SSO. In order to perform a single sign out, the quickest way is to set the cookie expiration to a past date &#8211; this ensures that the cookie won&#8217;t be used by any application for authentication.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c88cfe61-056b-4e28-bb84-8da16bb7011e" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">protected void Logout (string strUserName)
{
  System.Web.HttpCookie cookie; 

  cookie = FormsAuthentication.GetAuthCookie(strUserName, false);
  cookie.Domain = "domain1.com";
  cookie.Expires = DateTime.Now.AddDays (-1);
  Response.AppendCookie (cookie);
}</pre>
</div>
<h3>Integrating Web Applications</h3>
<p>What said so far is valid if applications use the same database to store user profiles. But what if 2 applications use each one their own database?</p>
<p>In this case, the SSO works, but sooner or later one of the applications will throw exceptions due to missing data in its database. If a user registers in application A, once he signs in he can access to application B &#8211; but he never registered in application B, so application B doesn&#8217;t have this user in its database.</p>
<p>This is the case when, for example, we have to integrate 2 existing applications, which already have their own authentication and registration implemented.</p>
<p>To solve this problem, we have 2 choices:</p>
<ul>
<li>modify both application in order to use a single authentication and registration process, and having a shared user profile repository </li>
<li>choose one application as the master application, and remove the authentication and registration process from the other application (the slave application) </li>
</ul>
<p>We&#8217;ll focus on the second solution.</p>
<p>This method requires that the database used by slave applications is accessible by the master application. This can be achieved by either:</p>
<ul>
<li>Create a single database which holds both application databases. In this case it would be good to use different prefixes for database entities to avoid naming conflicts &#8211; this could happen if both databases have a <span class="inline-code">Users </span>table. If we choose <span class="inline-code">mst </span>and <span class="inline-code">slv </span>as prefixes, we should rename the <span class="inline-code">Users </span>table to <span class="inline-code">mst_Users </span>for the master database and <span class="inline-code">slv_Users </span>for the slave database. This requires that we modify the source code and stored procedures. </li>
<li>Use 2 different databases, but the master application must be able to access to the slave&#8217;s database. </li>
</ul>
<p>Authentication should be performed in the following way:</p>
<ul>
<li>The user accesses to the master application, and signs in </li>
<li>The master application verifies the user&#8217;s credentials </li>
<li>The master application verifies whether the logged user is defined in the slave database &#8211; if not, accesses to the slave&#8217;s database and creates the new user </li>
<li>The master application calls (if existing) a slave&#8217;s stored procedure which performs post-authentication processing (such as setting a &quot;logged in&quot; field, inserting a new row in a history table, and so on) </li>
<li>The master application generates the SSO cookie </li>
</ul>
<p>User profile creation on the slave database requires that:</p>
<ul>
<li>the master application is able to access to the slave&#8217;s database </li>
<li>the slave&#8217;s database exposes a stored procedure which handles user registration (we may need to write it by ourselves) </li>
</ul>
<p>The second requirement isn&#8217;t mandatory, since it could also be achieved by using inline SQL &#8211; but I usually prefer the stored procedure solution.</p>
<h3>Final touch</h3>
<p>There would be a few final things to do on the slave application: </p>
<p></p>
<ul>
<li>Removal of all login links </li>
<li>Replacement of logout links with a &quot;Back to the Master application&quot; link </li>
<li>Replacement of all &quot;User&#8217;s profile&quot; links to point to the master application user&#8217;s profile page </li>
</ul>
<p>These steps ensure that navigation is consistent with integration &#8211; we&#8217;re supposing that all user&#8217;s info (credentials, profile, user&#8217;s preferences) are handled by the master application, so we need to modify the slave application accordingly. It is responsibility of the master application to update user&#8217;s profile in the slave application.</p>
<h3>What if different cookies are used?</h3>
<p>There may be cases where we want to keep authentication cookies separated from master and slaves applications. In this case we can&#8217;t share the authentication cookie among cooperating applications.</p>
<p>In this case the solution is to create an authentication cookie for the slave application from within the master application.</p>
<p>The code below creates an authentication cookie from the slave application:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c0e1ee3b-9216-4034-b2db-e6537705a614" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">FormsAuthenticationTicket ticket;
HttpCookie cookie;
string cookiestr; 

ticket = new FormsAuthenticationTicket(
                       1,
                       userId,
                       DateTime.Now,
                       DateTime.Now.AddYears (120),
                       true,
                       "User Data",
                       "cookie_path"
           ); 

cookiestr = FormsAuthentication.Encrypt(ticket);
cookie = new HttpCookie("cookie_name", cookiestr);
cookie.Expires = ticket.Expiration;
cookie.Path = "cookie_path"; 

Response.Cookies.Add(cookie); </pre>
</div>
<div class="focus-right">
<h3>Forms Authentication Ticket</h3>
<p>The <code class="inline-code">FormsAuthenticationTicket</code> class is used to create and read the values of a forms authentication cookie identifying an authenticated user. </p>
<p>Forms authentication tickets must be encrypted using the <span class="inline-code">FormsAuthentication.Encrypt()</span> method before being issued as a cookie. </p>
<p>More information about the&#160; <span class="inline-code">FormsAuthenticationTicket </span>class can be found <a href="http://msdn2.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx">here</a>.</div>
<p>The <code class="inline-code">FormsAuthenticationTicket</code>, as its name says, is a class used to generate authentication tickets (see the side box for more details). The code sample above shows that the following parameters are used to create the ticket:</p>
<ul>
<li>ticket version number </li>
<li>user id </li>
<li>date and time at which the ticket was generated </li>
<li>ticket expiration </li>
<li>whether creating a persistent cookie or limited to the current browser&#8217;s session </li>
<li>user specific data to be stored in the ticket (for example, this could be a user class) </li>
<li>cookie path </li>
</ul>
<h3>References</h3>
<p><a href="http://msdn2.microsoft.com/en-us/library/w8h3skw9.aspx">MSDN &#8211; machineKey element</a> </p>
<p><a href="http://msdn2.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx">MSDN &#8211; FormsAuthenticationTicket class</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/development/dotnet/single-sign-on-across-multiple-asp-net-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quickly add feed capabilities to your PHP application</title>
		<link>http://www.developer-corner.com/development/world-php/quickly-add-feed-capabilities-to-your-php-application/</link>
		<comments>http://www.developer-corner.com/development/world-php/quickly-add-feed-capabilities-to-your-php-application/#comments</comments>
		<pubDate>Sat, 29 Jul 2006 06:00:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[World.PHP]]></category>
		<category><![CDATA[php feeds]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/development/world-php/quickly-add-feed-capabilities-to-your-php-application/</guid>
		<description><![CDATA[FeedCreator is a small and very simple to use PHP library for adding feeds capabilities to PHP applications]]></description>
			<content:encoded><![CDATA[<p>Although feeds aren&#8217;t a new invention, lately they are getting more popular. Using feeds, we have an easy and convenient way to publish content, either news or any other sources (blogs, articles, etc.)</p>
<p>I had to implement feeding capabilities to a PHP application I&#8217;m working on, and I&#8217;ve been suggested to use <a href="http://www.bitfolge.de/rsscreator-en.html" target="_blank">FeedCreator</a>, an open source library written, by Kai Blankenhorn, which provides support for the following feeds:</p>
<div class="hint-right"></div>
<ul>
<li>RSS (0.91, 1.0, 2.0) </li>
<li>PIE (0.1) </li>
<li>MBOX </li>
<li>OPML </li>
<li>ATOM </li>
<li>HTML </li>
<li>JS </li>
</ul>
<p>The most diffused are undoubtedly RSS and Atom, but if you need less known format you can.</p>
<p>Adding feeds to your application is as simple as writing the following code (taken from the library documentation):</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:68492ccb-49ae-4a91-94c9-bb62d2ea175e" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">include("feedcreator.class.php"); 

$rss = new UniversalFeedCreator();
$rss-&gt;useCached(); // use cached version if age&lt;1 hour
$rss-&gt;title = "PHP news";
$rss-&gt;description = "daily news from the PHP scripting world"; 

//optional
$rss-&gt;descriptionTruncSize = 500;
$rss-&gt;descriptionHtmlSyndicated = true; 

$rss-&gt;link = "http://www.dailyphp.net/news";
$rss-&gt;syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"]; 

$image = new FeedImage();
$image-&gt;title = "dailyphp.net logo";
$image-&gt;url = "http://www.dailyphp.net/images/logo.gif";
$image-&gt;link = "http://www.dailyphp.net";
$image-&gt;description = "Feed provided by dailyphp.net. Click to visit."; 

//optional
$image-&gt;descriptionTruncSize = 500;
$image-&gt;descriptionHtmlSyndicated = true; 

$rss-&gt;image = $image; 

// get your news items from somewhere, e.g. your database:
mysql_select_db($dbHost, $dbUser, $dbPass);
$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC");
while ($data = mysql_fetch_object($res)) {
$item = new FeedItem();
$item-&gt;title = $data-&gt;title;
$item-&gt;link = $data-&gt;url;
$item-&gt;description = $data-&gt;short; 

//optional
item-&gt;descriptionTruncSize = 500;
item-&gt;descriptionHtmlSyndicated = true; 

$item-&gt;date = $data-&gt;newsdate;
$item-&gt;source = "http://www.dailyphp.net";
$item-&gt;author = "John Doe"; 

$rss-&gt;addItem($item);
} 

// valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated),
// MBOX, OPML, ATOM, ATOM0.3, HTML, JS
echo $rss-&gt;saveFeed("RSS1.0", "news/feed.xml");</pre>
</div>
<p>What makes it so special is that it is really simple to use.</p>
<p>The libray is open source, released under the LGPL license.</p>
<p>For more information and to download the library, click <a href="http://www.bitfolge.de/rsscreator-en.html" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/development/world-php/quickly-add-feed-capabilities-to-your-php-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to prevent validation errors from being displayed in CodeCharge Studio</title>
		<link>http://www.developer-corner.com/development/world-php/how-to-prevent-validation-errors-from-being-displayed-in-codecharge-studio/</link>
		<comments>http://www.developer-corner.com/development/world-php/how-to-prevent-validation-errors-from-being-displayed-in-codecharge-studio/#comments</comments>
		<pubDate>Wed, 12 Jul 2006 05:49:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[World.PHP]]></category>
		<category><![CDATA[php codecharge-studio]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/development/world-php/how-to-prevent-validation-errors-from-being-displayed-in-codecharge-studio/</guid>
		<description><![CDATA[When executing a postback on a form, for example to load the list of values for dependant list boxes, validation is performed and errors are displayed. How to prevent these errors from being displayed?]]></description>
			<content:encoded><![CDATA[<p>I have a registration form which uses 2 dependent list boxes Country and State, where State is populated basing on the Country selection. </p>
<p>To dynamically load the State list box I had to add a client <span class="inline-code">OnChange</span> event to the Country list box, which submits the form. But at this point the form displays all errors (mostly missing fields) and I don&#8217;t want this to happen. </p>
<p>This is the solution I found, which uses client side JavaScript: </p>
<p>The name of my form is <span class="inline-code">RegisteredUser</span> </p>
<ol>
<li>I have added a hidden field to the form, with name
<div class="inline-code">Validation, Control Source Type = &quot;<span class="inline-code">Code Expression</span>&quot;, type <span class="inline-code">Boolean </span>and default value = <span class="inline-code">True </span></div>
</li>
<li>I&#8217;ve added a client <span class="inline-code">OnChange</span> event to the Country list box, with the following code:       <br /> 
<div class="embedded-code-boxed">document.forms[&quot;RegisteredUser&quot;].Validation.value = &quot;No&quot;;        <br />document.forms[&quot;RegisteredUser&quot;].submit(); </div>
</li>
<li>In the HTML code, I&#8217;ve located the <span class="inline-code">{Errors}</span> row, and set the <span class="inline-code">id </span>and <span class="inline-code">name </span>attributes to <span class="inline-code">phErrors</span> &#8211; it should look like:
<div class="embedded-code-boxed">&lt;!&#8211; BEGIN Error &#8211;&gt;        <br />&lt;tr class=&quot;Error&quot; id=&quot;phErrors&quot; name=&quot;phErrors&quot;&gt;         <br />&#160; &lt;td colspan=&quot;2&quot;&gt;{Error}&lt;/td&gt;         <br />&lt;/tr&gt;         <br />&lt;!&#8211; END Error &#8211;&gt; </div>
</li>
<li>I&#8217;ve added a client <span class="inline-code">OnLoad </span>event to the form, with the following code:       <br /> 
<div class="embedded-code-boxed">var phErrors = document.getElementById (&quot;phErrors&quot;);        <br /> 
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:fb6b3f74-06a5-429d-ba26-4fad7b4efa3d" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">if (phErrors != null)
{
  if (document.forms["RegisteredUser"].Validation.value == "No")
  {
    document.forms["RegisteredUser"].Validation.value = "Yes";
    phErrors.style.visibility = "hidden";
    phErrors.style.position = "absolute";
  }
  else
  {
    phErrors.style.visibility = "visible";
    phErrors.style.position = "relative";
  }
}
</pre>
</div></div>
</li>
</ol>
<p>This code reads the value of the <span class="inline-code">Validation</span> hidden field: if the value is <span class="inline-code">No</span>, the <span class="inline-code">phErrors </span>row is hidden, otherwise it is shown.</p>
<p>It seems to work correctly, and also it shouldn&#8217;t add the row to the database, because the validation occurs at server side, but it isn&#8217;t displayed at client side (although included in the HTML). </p>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/development/world-php/how-to-prevent-validation-errors-from-being-displayed-in-codecharge-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to fight against spamming</title>
		<link>http://www.developer-corner.com/tech-area/how-to-fight-against-spamming/</link>
		<comments>http://www.developer-corner.com/tech-area/how-to-fight-against-spamming/#comments</comments>
		<pubDate>Tue, 11 Jul 2006 07:09:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[Tech Area]]></category>
		<category><![CDATA[spamfight]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/tech-area/how-to-fight-against-spamming/</guid>
		<description><![CDATA[I receive about 20 spam messages in my mailbox every day. I know this can be considered a low number, since I know of users receiving hundreds of spam, with a variety of subjects, ranging from porn sites to viagra, medicines, casino, software, etc. 
I wonder how can these spammers think that I'm so stupid to use my credit card to buy their products - but indeed I'm afraid that if they persist in their illegal business is because there are people who buy from them.

Anyway, what can we do to fight against them? There are several services which detect messages and prevent them from reaching our mail client, and mail client add-ons which move suspect messages into a spam folder, so that we don't have to waste time reading messages we aren't interested in. But is this a good way to fight spammers? Do they prevent spammers from sending you emails if you don't buy from them? Unfortunately I don't think so.

What can we do? Report spam.]]></description>
			<content:encoded><![CDATA[<p>I receive about 20 spam messages in my mailbox every day. I know this can be considered a low number, since I know of users receiving hundreds of spam, with a variety of subjects, ranging from porn sites to viagra, medicines, casino, software, etc.</p>
<div class="hint-left">SpamCop parses reported email, sending warning information to the internet service provider responsible for hosting the services used by the spammer</div>
<p>I wonder how can these spammers think that I&#8217;m so stupid to use my credit card to buy their products &#8211; but indeed I&#8217;m afraid that if they persist in their illegal business is because there are people who buy from them.</p>
<p>Anyway, what can we do to fight against them? There are several services which detect messages and prevent them from reaching our mail client, and mail client add-ons which move suspect messages into a spam folder, so that we don&#8217;t have to waste time reading messages we aren&#8217;t interested in. But is this a good way to fight spammers? Do they prevent spammers from sending you emails if you don&#8217;t buy from them? Unfortunately I don&#8217;t think so.</p>
<p>What can we do? Report spam. </p>
<p>Since Internet has no country borders, it&#8217;s quite unlikely that recurring to law leads to a result, although I think this could be done &#8211; but unfortunately it doesn&#8217;t happen.</p>
<p>The only thing I can do is to repay them with the same money: making them waste time. </p>
<div class="right-box"><script type=text/javascript><!--
google_ad_client = "pub-5133511524656449";
google_ad_width = 250;
google_ad_height = 250;
google_ad_format = "250x250_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "F59191";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "008000";
//--></script>How? I started my &quot;war&quot; by locating, for each spam email:</div>
<ul>
<li>the ISP used by the spammer to send the email </li>
<li>the web hosting company which hosts the site referenced in the spam email </li>
</ul>
<p>The next step was to write a complain email to both recipients, asking for the spammer&#8217;s account to be suspended. This way, the spammer needs to change ISP and move its website to another hosting provider. This is a cost of their business, and I&#8217;m sure spammers have planned it &#8211; and I also want to be sure to keep this cost high for them.</p>
<p>I was used to perform these actions manually, by reading the email header, and using tools such as nslookup to find what I needed, but this is undoubtedly a time consuming process, and I did it while the number of spams was less than 10 per day. </p>
<p>But there is a better way: a service where you simply have to report the mail body and headers, and it will take care of reverse-engineering the information required, automatically fill in complaint reports and send them to the proper recipients. Its name is SpamCop, and their website is <a href="http://www.spamcop.net">www.spamcop.net</a>. Although the service requires a subscription (quite low, since it is about 1$ for each Mbyte of reported spam), it can also be used for free, in this case with a delay screen which reminds about subscribing &#8211; about 10 seconds to wait before completing the spam email analysis.</p>
<p>This of course doesn&#8217;t guarantee that actions are taken against spammers. There are ISP which themselves fight against spammers, and once they receive reports they verify, and if required take their actions, which can range from deactivating the spammer&#8217;s accounts to charge them and using legal ways (but this last one is the least used &#8211; unfortunately).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/tech-area/how-to-fight-against-spamming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to better appreciate your most preferred language</title>
		<link>http://www.developer-corner.com/developers-point-of-view/how-to-better-appreciate-your-most-preferred-language/</link>
		<comments>http://www.developer-corner.com/developers-point-of-view/how-to-better-appreciate-your-most-preferred-language/#comments</comments>
		<pubDate>Tue, 04 Jul 2006 13:20:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[Developer's point of view]]></category>
		<category><![CDATA[development php java c#]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/developers-point-of-view/how-to-better-appreciate-your-most-preferred-language/</guid>
		<description><![CDATA[Is Java better than C#, C# better than C++, C++ better than Java? Are open sources technologies better than vendor specific technologies? 
I've seen a lot of developers telling that Linux is better than Windows, C# is better than Java, Delphi is better than VC++, and so on. But if you ask them if they know the other language they are comparing with, they say no.

I was one of them, since I believed that the best IDE was Delphi, the best platform was Windows, and the best language was C++. At least, until I started working on "real projects" and not on applications made just for fun. When I had to learn Java and use it to develop server applications on Sun platforms, I started to appreciate the language and the Unix-like environments.... and I started to believe that these technologies were better than those I thought were the best. Soon I realized that every technology is the best, depending on where it is applied.]]></description>
			<content:encoded><![CDATA[<h3>The universal technology</h3>
<p>I&#8217;ve seen a lot of developers telling that Linux is better than Windows, C# is better than Java, Delphi is better than VC++, and so on. But if you ask them if they know the other language they are comparing with, they say no.</p>
<p>I was one of them, since I believed that the best IDE was Delphi, the best platform was Windows, and the best language was C++. At least, until I started working on &quot;real projects&quot; and not on applications made just for fun. When I had to learn Java and use it to develop server applications on Sun platforms, I started to appreciate the language and the Unix-like environments&#8230;. and I started to believe that these technologies were better than those I thought were the best. Soon I realized that every technology is the best, depending on where it is applied.</p>
<blockquote><div class="hint-left">There is no universal technology or language which solves all problems</div>
</blockquote>
<p>Now I don&#8217;t believe anymore that there is the universal technology or language which solves all problems. Every time I start a new project, if the customer doesn&#8217;t have a specific preference, I always spend some time trying to understand what are the best tools to implement the project &#8211; and the result depends from the project itself. In web development my favorite preference is the .NET technology, for several reasons &#8211; but this is not a choice that can be done every time for every project. For example, if one of the requirements is that the application must run on open source environments, .NET wouldn’t be the proper choice.</p>
<h3>The proper tools</h3>
<p>During my professional experience I&#8217;ve tried to learn as many languages as possible. If I get confident knowledge of each language, I&#8217;m able to choose the best solution for every problem, from both the developer point of view (how simple or hard is the development using a specific language) as well as from the customer/project point of view (what are the benefits if I choose a technology instead of another). When I learned Java, I appreciated how life is easier with a memory manager which automatically disposes objects no longer referenced. When I learned C#, I appreciated the integration with the .NET technology, the foreach statement, but I also noticed how exception handling was better in Java, since exceptions must be explicitly handled within each method or the method itself must be declared to throw those exceptions which aren&#8217;t handled in its body. I also, and still, like the C++ philosophy: &quot;The developer always knows what he&#8217;s doing&quot;. This is the reason why C++ offers more power with pointers and access to memory. It&#8217;s irrelevant that it&#8217;s not always true the developer always knows what he is doing <img src='http://www.developer-corner.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  The key point is that you have the power to do almost everything, although at a price (usually more attention when dealing with pointers and dynamically allocated memory, and more debugging&#8230;.)</p>
<h3>PHP Revolution</h3>
<p>Lately I&#8217;ve appreciated a language I&#8217;ve used in the past, and which I didn&#8217;t like: PHP. The reason why I don&#8217;t like PHP is that I prefer strongly typed variables, variable declarations, as well as to know from the compiler if I wrote something wrong in my code, such as the name of a variable (a common mistake in PHP which leads to unpredictable results) or a function call (which usually leads to a run-time error). But I have to say that it&#8217;s extremely practical the ability to save your PHP code and test it immediately without the need of recompilation, deployment, etc. &#8211; a perfect solution for the project I&#8217;m currently working on. And I wouldn&#8217;t had chosen it if the customer hadn&#8217;t explicitly asked for it. <strong>We never stop learning</strong>!! Now I&#8217;ll definitively choose it again in the future, if the prerequisites for its usage are good, and the project will benefit from its usage.</p>
<h3>Can I say that C# is better than Java?</h3>
<p>Yes and no. It depends. As outlined above, in order to state that a language or technology is better than another, I need to:</p>
<ol>
<li>have proficient knowledge of both </li>
<li>compare pro and cons applied to a specific project </li>
</ol>
<p>But the result of the comparison is limited to the project &#8211; on a different project, the choice could be different:</p>
<ul>
<li>if I need to care about speed, maybe the best solution would be C++, but not for web applications </li>
<li>if I need portability, Java is best &#8211; but I wouldn&#8217;t choose it if the application has a user interface </li>
<li>if I need modularity and easy of development on a web application, my choice would fall on ASP.NET </li>
<li>if I need low licenses cost, the choice could be PHP, Java/JSP, or Ruby On Rails </li>
</ul>
<h3>Your opinion</h3>
<p>How do you choose the technologies and languages on your projects? Do you focus on a single technology, and use others only when the customer explicitly asks for them?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/developers-point-of-view/how-to-better-appreciate-your-most-preferred-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning by using</title>
		<link>http://www.developer-corner.com/developers-point-of-view/learning-by-using/</link>
		<comments>http://www.developer-corner.com/developers-point-of-view/learning-by-using/#comments</comments>
		<pubDate>Sun, 02 Jul 2006 07:33:00 +0000</pubDate>
		<dc:creator>Antonio Bello</dc:creator>
				<category><![CDATA[Developer's point of view]]></category>
		<category><![CDATA[learning]]></category>

		<guid isPermaLink="false">http://blog.developer-corner.com/uncategorized/learning-by-using/</guid>
		<description><![CDATA[Before using a new language or technology, we need to know what we are working with. What if we have no time to learn?]]></description>
			<content:encoded><![CDATA[<h3>The first computer</h3>
<p>I started dealing with development when I was 12, after I convinced my parents to buy me a computer. My choice fell on a Commodore Vic 20, a computer with a 1MHz CPU, 3582 bytes (bytes!!) of RAM memory, embedded basic language, and external memory storage based on a tape recorder.</p>
<p>I learned the computer principles, the way it works, the Basic language, the assembler language, how to deal with limited resources (such as memory) and how to develop software. I wrote a few games, just for fun &#8211; too young to think about how to make money with them <img src='http://www.developer-corner.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Since then, I have ever learned, learned and learned, and almost all of what I know I learned by myself. </p>
<h3>The first job</h3>
<p>When I&#8217;ve been contacted by a company for my first &quot;serious&quot; job, I&#8217;ve been subject to a 2 weeks test to implement some new features on an existing FoxPro application before getting a contract. Never worked with FoxPro before, nor had experience with its scripting language and more generally with database development (just a few theorical concepts).</p>
<p>So, during these 2 weeks, I studied and learned FoxPro, its language, and how to use databases. Life isn&#8217;t so easy, so 2 days before the end of my test period I had an HD failure, and of course I didn&#8217;t have any backup &#8211; all work was lost. Since it was a new HD, we brought it to the support center, asking to repair it but preserving the data, if possible &#8211; after 1 hour, a technician get back to us telling &quot;The hard disk is working so well that we&#8217;ve also formatted it&quot;. Panic.</p>
<p>Fortunately I&#8217;ve been able to recover all lost data by using an unformatting utility &#8211; with compliments of my boss, who told me &quot;I don&#8217;t know why, but I thought you were a database expert &#8211; I&#8217;ve just read your resume again, and I have no idea why I thought so. Anyway I like the way you work, so the job is yours&quot;.</p>
<p>My next task was a feasibility study about a QuickTime application running on a Mac to be used to display and record data retrieved from medical equipments &#8211; once again, I had no previous experience with QuickTime and Mac &#8211; nevertheless, this has been not only the first but also the last experience with a Mac <img src='http://www.developer-corner.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . In 1 week, the time given to complete this task, I provided the results of the feasibility study &#8211; which were positive.</p>
<h3>Learning by Using</h3>
<p>What do I want to say?</p>
<p>Sometimes we have to learn a new language or technology, but we have no time to learn it since we also have to apply it in the project we have to work on, and which, surprisingly, must be completed within yesterday.</p>
<p>I&#8217;m used to learn everything I need in my work by myself. This is undoubtedly a great advantage, since I don&#8217;t need to attend courses or use other forms of slow &quot;formal learning&quot;.</p>
<p>What I mostly like is the ability to learn a new language or technology by using it on a real project. Of course this can&#8217;t be done without having a proficient knowledge of the area being explored. If somebody has never developed or learned a programming language, it&#8217;s extremely unlikely he will be able to learn using this learning pattern.</p>
<p>But if, for instance, you have done web development before, using ASP.NET, it wouldn&#8217;t be difficult to move on PHP. Once you&#8217;ve acquired what web development means, what you expect to do and what tools you have to use and you are allowed to use, you&#8217;re able to transpose this knowledge on the new language &#8211; it&#8217;s just a matter of translating what you already know in a new context. You expect that, independently from the language you use, there is a way to handle sessions and cookies, to access to a database, to handle data submitted in a form, etc.</p>
<p>This is the reason why I like to learn new languages and technologies. I like the challenge of starting from a virtually unknown area, performing analysis and design on a real project basing on a few information I read here and there, and starting the development phase while starting the learning process at the same time. This process undoubtedly slows the development at beginning, to proceed at increased speed from day to day. And while proceeding with the learning process you also realize what you&#8217;ve made wrong &#8211; this sometimes requires re-working on the work made in the past days, but this way you better understand what you did wrong and you (hopefully) won&#8217;t do it again.</p>
<h3>Formal learning</h3>
<div class="hint-left">Actual knowledge is not as important as the ability to acquire that knowledge</div>
<p>Of course the &quot;learning by using&quot; pattern cannot be considered better than formal learning paths. Attending a course has its advantages, since who is teaching has proficient knowledge (or at least we hope he has <img src='http://www.developer-corner.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ) and he can better show the key points and focus on the most important things to know, as well as explain best practices, things to know, things to avoid, and so on.</p>
<p>Also, reading a good book and doing practice, following code, examples and exercises, helps to get knowledge. Anyway I usually skip all of these extra activities, since I prefer to focus on understanding what the writer want to expose, catching the key points, just to know that &quot;they exist&quot; &#8211; when I need to use a specific feature, I know it is there, and I just have to browse the documentation to know how to use it.</p>
<h3>Knowledge or Pointers?</h3>
<div class="hint-right">Ability to find pointers to knowledge is more important than actual knowledge</div>
<p>What I&#8217;ve just written above points me to the following consideration. </p>
<p>I strongly believe that actual knowledge is not as important as the ability to acquire that knowledge. Long time ago I&#8217;ve been told &quot;it&#8217;s not important if you have a specific knowledge &#8211; I care more if you are able to find the pointers to that knowledge&quot;.</p>
<h3>Conclusions</h3>
<p>Traditional learning (either school, courses, and so on) is important. But it isn&#8217;t enough. Being able to self-learn helps when you have no time to use the traditional learning paths. Being able to learn while applying what you&#8217;re learning is an extra gear. Being able to update your knowledge &quot;on demand&quot; is a double extra gear.</p>
<p>What are your learning methodologies? Do you want to add any comment, suggestion, or extend this discussion? Just write below&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developer-corner.com/developers-point-of-view/learning-by-using/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
