<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;D0UCSHg_fCp7ImA9WhRaFEU.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845</id><updated>2012-02-17T05:27:49.644-08:00</updated><category term="wcf" /><category term="interface" /><category term="c#" /><category term="Code Snippets" /><category term="multiple-inheritance" /><category term="css" /><category term="javascript" /><category term="Technology" /><category term="authentication" /><category term="html-encode" /><category term="software-design" /><category term="security" /><category term="shy" /><category term="OOP" /><category term="user-controls" /><category term="asp.net" /><category term="custom-controls" /><category term="Software Architecture" /><category term="solid-state-drive" /><category term="Articles" /><category term="password" /><category term="authorization" /><title>Musings of a curious mind</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://blog.hemanshubhojak.com/" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/MusingsOfACuriousMind" /><feedburner:info uri="musingsofacuriousmind" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;D0UCSHg-cSp7ImA9WhRaFEU.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-4493411289046199703</id><published>2012-02-16T12:25:00.000-08:00</published><updated>2012-02-17T05:27:49.659-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-17T05:27:49.659-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="password" /><category scheme="http://www.blogger.com/atom/ns#" term="security" /><title>Security considerations for storing passwords in a database</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/nRxeAEdX4DHGUEuNi3vnwt3hHHw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nRxeAEdX4DHGUEuNi3vnwt3hHHw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/nRxeAEdX4DHGUEuNi3vnwt3hHHw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nRxeAEdX4DHGUEuNi3vnwt3hHHw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;It is a common practice to store user names and passwords in a database. This can be done in the following ways&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Store it in clear text&lt;/li&gt;
&lt;li&gt;Encrypt and store&lt;/li&gt;
&lt;li&gt;Store a hash of the password instead of the password itself&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Lets examine the pros and cons of all of the above methods.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-size: large;"&gt;Store it in clear text&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
Anyone having access to the database can read the passwords and has an option to misuse it. It is not recommended to store passwords in clear text.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-size: large;"&gt;Encrypt and store&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
This is better than storing in clear text as it is not human readable. The security however depends on the encryption algorithm used. If a hacker manages to crack the encryption algorithm then all the passwords are compromised.&amp;nbsp;Use a strong encryption algorithm with a salt to minimize the threat. Almost all encryption algorithms can be cracked, but most of them will take more than a year for a super computer. Considering a probability that the user will change the password once in a year, it becomes impossible to crack. Consider having a password policy where you use a fairly long password (min 5 characters with special characters, upper and lower case alphabets and numbers) which will require many combinations before it can be tried.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-size: large;"&gt;Store a hash of the password instead of the password itself&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;
This is one of the best ways to store the passwords.&amp;nbsp;In fact, you actually don't store the password but its hash.&amp;nbsp;The problem with this approach is that you cannot recover the password. Every time the user forgets his password you will have to generate a new password and send it to him using which he can set a new password. The good thing about this approach is that even if a hacker manages to crack one password rest are secured. This will give you a lead time to handle the security breach. These hashes are also prone to dictionary attacks.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
One more option that comes to my mind is to store an encrypted hash which gives a double layer of security. Now the choice actually depends on the security requirements of your application. Advanced security may also hamper the performance. It is a fine balance that an architect has to make.&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-4493411289046199703?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/Bu79zr3C_go" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/4493411289046199703/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2012/02/security-considerations-for-storing.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/4493411289046199703?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/4493411289046199703?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/Bu79zr3C_go/security-considerations-for-storing.html" title="Security considerations for storing passwords in a database" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2012/02/security-considerations-for-storing.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE8EQHg6eSp7ImA9WhRaFE8.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-285772504042558699</id><published>2012-02-16T12:06:00.000-08:00</published><updated>2012-02-16T12:06:41.611-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-16T12:06:41.611-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="authorization" /><category scheme="http://www.blogger.com/atom/ns#" term="authentication" /><category scheme="http://www.blogger.com/atom/ns#" term="wcf" /><title>Custom Authentication and Authorization in WCF</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/xMMZL6AWTS1Me9asxmlCaxRdRSw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xMMZL6AWTS1Me9asxmlCaxRdRSw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/xMMZL6AWTS1Me9asxmlCaxRdRSw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xMMZL6AWTS1Me9asxmlCaxRdRSw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;Recently I had to implement a restful web service with a custom token based security for it. The following is a strategy for a typical token based security&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Client calls the authenticate operation passing the user name and password&lt;/li&gt;
&lt;li&gt;The web service authenticates the clients credentials and issues a token with some expiry time&lt;/li&gt;
&lt;li&gt;The client will then pass this token to each subsequent call to the web service&lt;/li&gt;
&lt;li&gt;Before every call the web service will verify the token before allowing access to the operation&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
There are two things that needs to be done, authentication and authorization. WCF provides two classes for doing this, ServiceAuthenticationManager and ServiceAuthorizationManager. We can create our own custom authentication and authorization classes by inheriting from these classes respectively. These classes can then be configured in the web.config for use in our web service. In the next post I will demonstrate how this can be done.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Keep watching.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-285772504042558699?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/kbb9fnap5tU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/285772504042558699/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2012/02/custom-authentication-and-authorization.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/285772504042558699?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/285772504042558699?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/kbb9fnap5tU/custom-authentication-and-authorization.html" title="Custom Authentication and Authorization in WCF" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2012/02/custom-authentication-and-authorization.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ANRX0zfyp7ImA9WhRaFE8.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-576762171574765726</id><published>2012-02-16T11:49:00.001-08:00</published><updated>2012-02-16T11:49:54.387-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-16T11:49:54.387-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="software-design" /><category scheme="http://www.blogger.com/atom/ns#" term="OOP" /><title>Avoid over engineering</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ErdnNnXfqiIii-fzJG2jrGv_SuE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ErdnNnXfqiIii-fzJG2jrGv_SuE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ErdnNnXfqiIii-fzJG2jrGv_SuE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ErdnNnXfqiIii-fzJG2jrGv_SuE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;Most application developers tend to over engineer the application design by having objects for almost anything. This adds to the complexity and makes it really difficult to manage. Take this case for example, you need to create a web service which will be accessed by clients over http. You are supposed to implement the token based security for accessing this web service. In a token based security strategy, the client first makes a call to the authenticate method of the web service with a user name and password. The web service will validate the credentials and issue a token with some expiry date and time. The clients will then pass this token in the http header every time they make a call the web service.&lt;br /&gt;
&lt;br /&gt;
The best place to verify this token is somewhere before the web service operation is called instead of verifying it inside all the operations as this is going to be common for all operations in that web service. We now have two places where tokens are used, one inside the authenticate method and the other where we verify the tokens. We can create a token manager class which will be responsible for issuing and verifying the tokens. This class can then be used. This is a good design where the responsibility of token manager is inside one common class.&lt;br /&gt;
&lt;br /&gt;
There is however one more option, we create an interface called ITokenManager instead of a class. We then inject an implementation at run-time. This gives us a flexibility to switch the implementation at run-time if we ever wish to change the way the tokens are issued and verified (e.g. you can switch from XML file to SQL Database). This is a good approach to a flexible design but we are at this point introducing complexity. What if we issue tokens not based on user name and password but something else. In which case we will have to change the interface definition and all hell breaks loose.&lt;br /&gt;
&lt;br /&gt;
Now I am talking about application development and not any framework development, in which case this would have been a better design and not an OO overkill. In an application design it is always experienced that it is better to follow the &lt;a href="http://en.wikipedia.org/wiki/You_ain't_gonna_need_it" target="_blank"&gt;YAGNI &lt;/a&gt;or the &lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" target="_blank"&gt;DRY&lt;/a&gt; principal so that we are always on track and focus on the current problem at hand rather than designing for some future possibilities which may not come or will come in a form which is altogether different than the current.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-576762171574765726?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/fmEDWMiJFCQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/576762171574765726/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2012/02/avoid-over-engineering.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/576762171574765726?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/576762171574765726?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/fmEDWMiJFCQ/avoid-over-engineering.html" title="Avoid over engineering" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2012/02/avoid-over-engineering.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkYCR3w_cCp7ImA9WhRXEko.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-5094458153664881358</id><published>2011-12-18T21:56:00.000-08:00</published><updated>2011-12-18T21:56:06.248-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-18T21:56:06.248-08:00</app:edited><title>Switched to google blogger</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_0FRWoslttEisyDYLi1F8mYS_Ho/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_0FRWoslttEisyDYLi1F8mYS_Ho/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_0FRWoslttEisyDYLi1F8mYS_Ho/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_0FRWoslttEisyDYLi1F8mYS_Ho/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;Finally I have shifted my blog from Wordpress to Google Blogger :)&lt;br /&gt;
&lt;br /&gt;
The new blogger interface is very refreshing and also very user friendly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-5094458153664881358?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/_E3upBVUGoc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/5094458153664881358/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2011/12/switched-to-google-blogger.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/5094458153664881358?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/5094458153664881358?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/_E3upBVUGoc/switched-to-google-blogger.html" title="Switched to google blogger" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2011/12/switched-to-google-blogger.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYHR387eip7ImA9WhRQEUo.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-3322050331951587877</id><published>2011-01-08T09:57:00.000-08:00</published><updated>2011-12-06T03:15:36.102-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-06T03:15:36.102-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Code Snippets" /><title>Removing time from an sql datetime value</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0jqXzze583WwwPR0EYIdmEmG4Vw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0jqXzze583WwwPR0EYIdmEmG4Vw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0jqXzze583WwwPR0EYIdmEmG4Vw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0jqXzze583WwwPR0EYIdmEmG4Vw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;The following trick can be used to remove (set it to zero) time from an sql datetime value.&lt;br/&gt;&lt;pre class="brush:sql"&gt;&lt;br/&gt;SELECT CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)&lt;br/&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-3322050331951587877?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/_XnB6imnHYU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/3322050331951587877/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2011/01/removing-time-from-sql-datetime-value.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/3322050331951587877?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/3322050331951587877?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/_XnB6imnHYU/removing-time-from-sql-datetime-value.html" title="Removing time from an sql datetime value" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2011/01/removing-time-from-sql-datetime-value.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYHR386fSp7ImA9WhRQEUo.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-4118967738681600896</id><published>2010-10-27T22:25:00.000-07:00</published><updated>2011-12-06T03:15:36.115-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-06T03:15:36.115-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="multiple-inheritance" /><category scheme="http://www.blogger.com/atom/ns#" term="interface" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="Software Architecture" /><category scheme="http://www.blogger.com/atom/ns#" term="Articles" /><title>Multiple Inheritance and Interfaces</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/QXWSvFARQRWzaonkb-Fjbnfkdrs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QXWSvFARQRWzaonkb-Fjbnfkdrs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/QXWSvFARQRWzaonkb-Fjbnfkdrs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QXWSvFARQRWzaonkb-Fjbnfkdrs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;When we say we inherit from a class, what is it that we actually inherit?&lt;br/&gt;&lt;br/&gt;We inherit the state and behavior of the class. Properties and variables define the state of a class and methods define the behavior.&lt;br/&gt;&lt;br/&gt;But when we talk about interfaces, do they have state and behavior? &lt;br/&gt;&lt;br/&gt;They don't, as you can only define signatures in an interfaces. Any class implementing this interface must provide the behavior and can have dependent state. &lt;br/&gt;&lt;br/&gt;It is very obvious that we &lt;strong&gt;implement an interface and not inherit from it&lt;/strong&gt;.&lt;br/&gt;&lt;br/&gt;Many modern languages have learned from the older languages and choose not to support multiple inheritance because of the &lt;a href="http://en.wikipedia.org/wiki/Diamond_problem"&gt;problems&lt;/a&gt; that they have. C# for that instance does not provide multiple inheritance.&lt;br/&gt;&lt;br/&gt;There is a misconception that interfaces can be used to implement multiple inheritance in C#. But this is not true, as they do not have anything (state or behavior) that can be inherited.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-4118967738681600896?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/lzhVSpJXC1s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/4118967738681600896/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2010/10/multiple-inheritance-and-interfaces.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/4118967738681600896?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/4118967738681600896?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/lzhVSpJXC1s/multiple-inheritance-and-interfaces.html" title="Multiple Inheritance and Interfaces" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2010/10/multiple-inheritance-and-interfaces.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYHR385cCp7ImA9WhRQEUo.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-990931509616385385</id><published>2010-09-04T09:27:00.000-07:00</published><updated>2011-12-06T03:15:36.128-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-06T03:15:36.128-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><category scheme="http://www.blogger.com/atom/ns#" term="solid-state-drive" /><title>Solid State Drives (SSD) Now Available in India</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/d3ib5n_LzfYCxCkwPj1CzDxsedE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d3ib5n_LzfYCxCkwPj1CzDxsedE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/d3ib5n_LzfYCxCkwPj1CzDxsedE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d3ib5n_LzfYCxCkwPj1CzDxsedE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;A couple of months back I was looking at upgrading my computer. Specifically I wanted to upgrade my disk space. While searching on the internet I stumbled upon a new technology (it is kinda old as we all use it currently) &lt;a href="http://en.wikipedia.org/wiki/Solid-state_drive"&gt;Solid State Drives&lt;/a&gt;. It is similar to the flash memory drives (pen drives) that we use, except that these are available in higher capacities (160GB, 190GB and so on). The advantage of this technology is&lt;br/&gt;&lt;ul&gt;&lt;br/&gt;	&lt;li&gt;It has no moving parts, hence no wear and tear (long lasting)&lt;/li&gt;&lt;br/&gt;	&lt;li&gt;Since it has no moving parts the seek time is almost zero. So the SDD will take very little time while saving and retrieving data (high performance).&lt;/li&gt;&lt;br/&gt;&lt;/ul&gt;&lt;br/&gt;&lt;br/&gt;The only disadvantage is that it is very expensive and is not available in very high capacities. On the brighter side, since it is already &lt;a href="http://www.theitdepot.com/products-Hard+Drives+HDD_C12.html"&gt;launched&lt;/a&gt; in India we can expect the prices to go down as the market for SSD opens up. Till that time I am planning to buy an internal 1TB SATA HDD ;).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-990931509616385385?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/BIUC-Kq2K3Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/990931509616385385/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2010/09/solid-state-drives-ssd-now-available-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/990931509616385385?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/990931509616385385?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/BIUC-Kq2K3Q/solid-state-drives-ssd-now-available-in.html" title="Solid State Drives (SSD) Now Available in India" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2010/09/solid-state-drives-ssd-now-available-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkIFRnczeCp7ImA9WhRXEkQ.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-7914087126570414550</id><published>2010-08-25T22:43:00.000-07:00</published><updated>2011-12-19T03:35:17.980-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-19T03:35:17.980-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="custom-controls" /><category scheme="http://www.blogger.com/atom/ns#" term="asp.net" /><category scheme="http://www.blogger.com/atom/ns#" term="user-controls" /><category scheme="http://www.blogger.com/atom/ns#" term="Articles" /><title>UserControl as a DLL made easy</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OF5EVbio_0OWXIbFpN7PgLWa4Uc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OF5EVbio_0OWXIbFpN7PgLWa4Uc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OF5EVbio_0OWXIbFpN7PgLWa4Uc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OF5EVbio_0OWXIbFpN7PgLWa4Uc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;To create controls in asp.net there are two options available.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Custom Controls&lt;/li&gt;
&lt;li&gt;User Controls&lt;/li&gt;
&lt;/ul&gt;
User controls cannot be compiled into a dll and redistributed while a custom control can be compiled into a dll. But a custom control does not have separate files to hold your markup and code which user controls have.&lt;br /&gt;
&lt;br /&gt;
If I can have separate files for markup and code in custom controls, its the best option for creating redistributable custom controls. This will make my design clean as I will achieve a clear separation of concern between my presentation (markup) and behavior (code). &lt;br /&gt;
&lt;br /&gt;
Currently this option is not available in asp.net but there is a &lt;a href="http://www.codegolem.com/post/UserControl-as-a-DLL-made-easy.aspx"&gt;nice article&lt;/a&gt; to achieve this. The code is also clean and does not pass as a hack but a proper way to create custom controls.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-7914087126570414550?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/e6jsCJkij6g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/7914087126570414550/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2010/08/usercontrol-as-dll-made-easy.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/7914087126570414550?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/7914087126570414550?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/e6jsCJkij6g/usercontrol-as-dll-made-easy.html" title="UserControl as a DLL made easy" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2010/08/usercontrol-as-dll-made-easy.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYHR34yfCp7ImA9WhRQEUo.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-2184003763127968921</id><published>2010-06-30T02:49:00.000-07:00</published><updated>2011-12-06T03:15:36.094-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-06T03:15:36.094-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="javascript" /><category scheme="http://www.blogger.com/atom/ns#" term="Code Snippets" /><category scheme="http://www.blogger.com/atom/ns#" term="html-encode" /><title>HTML Encode Text in JavaScript</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/I9d0Hca3NYBS9fyNChCoUiK1dU8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/I9d0Hca3NYBS9fyNChCoUiK1dU8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/I9d0Hca3NYBS9fyNChCoUiK1dU8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/I9d0Hca3NYBS9fyNChCoUiK1dU8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;There are many ways of HTML encoding text in JavaScript. You may use string replacement using RegEx or simply hardcode replacements. These approaches help solve the purpose but make the code bloated and difficult to maintain. There is one clean way of achieving this.&lt;br/&gt;&lt;br/&gt;&lt;pre class="brush:javascript"&gt;&lt;br/&gt;function HTMLEncode(value){&lt;br/&gt;     var div = document.createElement(“DIV”);&lt;br/&gt;     var textNode = document.createTextNode(value);&lt;br/&gt;     div.appendChild(textNode);&lt;br/&gt;     return div.innerHTML;&lt;br/&gt;}&lt;br/&gt;&lt;/pre&gt;&lt;br/&gt;&lt;br/&gt;The above code will html encode your text in a cleaner and faster way&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-2184003763127968921?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/wC632y-bVpE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/2184003763127968921/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2010/06/html-encode-text-in-javascript.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/2184003763127968921?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/2184003763127968921?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/wC632y-bVpE/html-encode-text-in-javascript.html" title="HTML Encode Text in JavaScript" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2010/06/html-encode-text-in-javascript.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYHR387cCp7ImA9WhRQEUo.&quot;"><id>tag:blogger.com,1999:blog-832381043314504845.post-4026729860444695729</id><published>2010-06-30T02:02:00.000-07:00</published><updated>2011-12-06T03:15:36.108-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-06T03:15:36.108-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="javascript" /><category scheme="http://www.blogger.com/atom/ns#" term="Code Snippets" /><category scheme="http://www.blogger.com/atom/ns#" term="shy" /><category scheme="http://www.blogger.com/atom/ns#" term="css" /><title>Wrap long lines using CSS and JavaScript</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MxsJotcp-4TxatsNM8A0HIVjDNw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MxsJotcp-4TxatsNM8A0HIVjDNw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MxsJotcp-4TxatsNM8A0HIVjDNw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MxsJotcp-4TxatsNM8A0HIVjDNw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;I had this annoying problem of long unwrap-able lines breaking my website  layout. After experimenting many fixes I finally settled on the following fix.&lt;br/&gt;&lt;br/&gt;&lt;code&gt;&lt;br/&gt;&lt;pre class="brush:javascript"&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br/&gt;     $(function(){&lt;br/&gt;          $(".wrap").each(function(){&lt;br/&gt;               $(this).html(&lt;br/&gt;                    $(this)&lt;br/&gt;                         .text()&lt;br/&gt;                         .replace(/([^\s-]{5})/g, "$&amp;amp;&amp;amp;shy;")&lt;br/&gt;                    );&lt;br/&gt;          });&lt;br/&gt;     });&lt;br/&gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;br/&gt;&lt;/code&gt;&lt;br/&gt;&lt;br/&gt;The above code uses &lt;strong&gt;jQuery &lt;/strong&gt;and&lt;strong&gt; Regular Expression&lt;/strong&gt; to wrap  text in tags which have the class "&lt;strong&gt;wrap&lt;/strong&gt;" by adding &lt;strong&gt;&amp;amp;shy;&lt;/strong&gt; after  every 5 characters in a long word. For more information on &lt;strong&gt;&amp;amp;shy; &lt;/strong&gt;refer the references section below.&lt;br/&gt;&lt;br/&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;br/&gt;&lt;ul&gt;&lt;br/&gt;	&lt;li&gt;&lt;a href="http://www.cs.tut.fi/~jkorpela/shy.html"&gt;http://www.cs.tut.fi/~jkorpela/shy.html&lt;/a&gt;&lt;/li&gt;&lt;br/&gt;	&lt;li&gt;&lt;a href="http://www.quirksmode.org/oddsandends/wbr.html"&gt;http://www.quirksmode.org/oddsandends/wbr.html&lt;/a&gt;&lt;/li&gt;&lt;br/&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/832381043314504845-4026729860444695729?l=blog.hemanshubhojak.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MusingsOfACuriousMind/~4/WY9UVOv5mkM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.hemanshubhojak.com/feeds/4026729860444695729/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.hemanshubhojak.com/2010/06/wrap-long-lines-using-css-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/4026729860444695729?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/832381043314504845/posts/default/4026729860444695729?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MusingsOfACuriousMind/~3/WY9UVOv5mkM/wrap-long-lines-using-css-and.html" title="Wrap long lines using CSS and JavaScript" /><author><name>Hemanshu Bhojak</name><uri>https://profiles.google.com/109059483499952713694</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-XZiF5xO1Xek/AAAAAAAAAAI/AAAAAAAABXQ/-_nVzRsrAlc/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://blog.hemanshubhojak.com/2010/06/wrap-long-lines-using-css-and.html</feedburner:origLink></entry></feed>

