<?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>m&#178;tec &#187; Scripting</title>
	<atom:link href="http://m2tec.be/blog/category/scripting/feed" rel="self" type="application/rss+xml" />
	<link>http://m2tec.be/blog</link>
	<description></description>
	<lastBuildDate>Fri, 11 Feb 2011 22:55:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Weard StackTrace behaviour</title>
		<link>http://m2tec.be/blog/2010/10/31/weard-stacktrace-behaviour-00149</link>
		<comments>http://m2tec.be/blog/2010/10/31/weard-stacktrace-behaviour-00149#comments</comments>
		<pubDate>Sun, 31 Oct 2010 15:28:02 +0000</pubDate>
		<dc:creator>Tom V</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[vb.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[CallStack]]></category>
		<category><![CDATA[PropertyChanged]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://m2tec.be/blog/?p=149</guid>
		<description><![CDATA[A colleague noticed that changing a combobox wasn&#8217;t showing the changes in the text fields below. When testing, I saw it WAS working. But with the click-once application not. After some time I noticed running the release without visual studio, it didn&#8217;t work. Although it worked when running with visual studio. Also the debug version [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague noticed that changing a combobox wasn&#8217;t showing the changes in the text fields below.<br />
When testing, I saw it WAS working. But with the click-once application not.<br />
After some time I noticed running the release without visual studio, it didn&#8217;t work.<br />
Although it worked when running with visual studio. Also the debug version was working.</p>
<p>For binding the text fields to my object I simply used a property: &#8220;Regime&#8221;.<br />
The (work)regime has 10 properties: id, user(id), &#8220;Monday&#8221; till &#8220;Sunday&#8221; and &#8220;weektotal&#8221;.<br />
All these properties raise an event by calling &#8220;PropChanged()&#8221;.<br />
This method would look up into the call stack wich method called him. Properties get set_ and get_ before the property-name as method.<br />
This way I could test it was ending with &#8220;day&#8221; and then also raise a &#8220;weektotal&#8221;-changed event, as this property is readonly and actualy a property for binding the total of all days.</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">propChanged</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://m2tec.be/blog/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://m2tec.be/blog/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://m2tec.be/blog/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://m2tec.be/blog/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="vbnet" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw2">Private</span> <span class="kw6">Sub</span> PropChanged<span class="br0">&#40;</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1"> <span class="co1">'Get the stacktrace and get the calling method</span></div></li><li class="li1"><div class="de1"> <span class="kw6">Dim</span> stack <span class="kw2">As</span> Diagnostics.<span class="me1">StackTrace</span> <span class="sy0">=</span> <span class="kw2">New</span> System.<span class="me1">Diagnostics</span>.<span class="me1">StackTrace</span></div></li><li class="li1"><div class="de1"> <span class="kw6">Dim</span> <span class="kw1">method</span> <span class="kw2">As</span> Reflection.<span class="me1">MethodBase</span> <span class="sy0">=</span> stack.<span class="me1">GetFrame</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>.<span class="me1">GetMethod</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div></li><li class="li2"><div class="de2"> <span class="co1">'Methods starting with &quot;set_&quot; are the properties</span></div></li><li class="li1"><div class="de1"> <span class="kw6">If</span> <span class="kw1">method</span>.<span class="me1">Name</span>.<span class="me1">ToLower</span>.<span class="me1">StartsWith</span><span class="br0">&#40;</span><span class="st0">&quot;set_&quot;</span><span class="br0">&#41;</span> <span class="kw2">Then</span></div></li><li class="li1"><div class="de1">  <span class="co1">'remove the &quot;set_&quot; and raise the event with the propertyname</span></div></li><li class="li1"><div class="de1">  <span class="kw6">RaiseEvent</span> PropertyChanged<span class="br0">&#40;</span><span class="kw2">Me</span>, <span class="kw2">New</span> PropertyChangedEventArgs<span class="br0">&#40;</span><span class="kw1">method</span>.<span class="me1">Name</span>.<span class="me1">Substring</span><span class="br0">&#40;</span><span class="nu0">4</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">  <span class="co1">'when the day changes, the total is also changed</span></div></li><li class="li2"><div class="de2">  <span class="kw6">If</span> <span class="kw1">method</span>.<span class="me1">Name</span>.<span class="me1">EndsWith</span><span class="br0">&#40;</span><span class="st0">&quot;day&quot;</span><span class="br0">&#41;</span> <span class="kw2">Then</span></div></li><li class="li1"><div class="de1">   <span class="kw6">RaiseEvent</span> PropertyChanged<span class="br0">&#40;</span><span class="kw2">Me</span>, <span class="kw2">New</span> PropertyChangedEventArgs<span class="br0">&#40;</span><span class="st0">&quot;weektotal&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">  <span class="kw6">End</span> <span class="kw6">If</span></div></li><li class="li1"><div class="de1"> <span class="kw6">End</span> <span class="kw6">If</span></div></li><li class="li1"><div class="de1"><span class="kw6">End</span> <span class="kw6">Sub</span></div></li></ol></pre></div></div>
<p>In a combobox I had a list of &#8220;presets&#8221; and when I select one, I update the &#8220;Regime&#8221;, to have the same values. Now, this wasn&#8217;t working.<br />
After like testing everything, for fun I showed a messagebox with the method.Name property.<br />
This let only see: &#8220;.createWorkRegime&#8221;, a complete surprise as it was actualy called by the Property &#8220;Monday&#8221; or &#8220;Tuesday&#8221; etc.</p>
<p>Obvious, when adding the plain RaiseEvent PropertyChanged, the binding works.<br />
I didn&#8217;t figured out why this happens, but it looks like the call-stack is changed when using properties in the constructor.<br />
I really don&#8217;t understand it as it&#8217;s only having this behavior when used in the constructor.</p>
<p>So it is changing the callstack AND ONLY when its runned from release (and directly the exe and not by visual studio)</p>
<p>If someone knows why this is happening, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://m2tec.be/blog/2010/10/31/weard-stacktrace-behaviour-00149/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java MD5 (hex)</title>
		<link>http://m2tec.be/blog/2010/02/03/java-md5-hex-0093</link>
		<comments>http://m2tec.be/blog/2010/02/03/java-md5-hex-0093#comments</comments>
		<pubDate>Wed, 03 Feb 2010 17:51:29 +0000</pubDate>
		<dc:creator>Tom V</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://m2tec.be/blog/?p=93</guid>
		<description><![CDATA[I needed to make a program in java which logins with the vBulletin login system. As you may know, many php boards use MD5 for hashing passwords. vBulletin uses a &#8220;more advanced way&#8221; of hashing, just like phpBB3. phpBB2 used just old plain MD5 hashes. So I needed to find out how I could use MD5 in [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to make a program in java which logins with the vBulletin login system.<br />
As you may know, many php boards use MD5 for hashing passwords.<br />
vBulletin uses a &#8220;more advanced way&#8221; of hashing, just like phpBB3. phpBB2 used just old plain MD5 hashes.<br />
So I needed to find out how I could use MD5 in java.</p>
<p>Off course there is no MD5 function like in php .<br />
That&#8217;s why I searched a function that can do it, a little search on google like &#8220;java MD5 function&#8221; and so I looked at the first pages links and tried the functions that weren&#8217;t too long.</p>
<h1>FAIL</h1>
<p>I created the vBulletin login system in java and with the first test account I could login &#8230;. BUT my own login failed <img src='http://m2tec.be/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> . Quite irritating if you try 10 passes, all work and when you put it live, many people complaining they can&#8217;t login&#8230;</p>
<p>As I got &#8220;lucky&#8221; with my pass, I found that my hashed login was wrong, so after some debugging I found a 0 (zero) was missing in the first MD5. So the MD5 function was WRONG:(</p>
<p>As a test, I created a program that creates random passwords and create the MD5 of it with the functions I found on different sites (found by using  google).</p>
<h3>Extra info</h3>
<p>Both MySQL and php&#8217;s MD5 function has a hex notation, clearly not all MD5-functions found are hex notated, this is not a must, but off course needed for being compatible with php/MySQL.</p>
<h1>The problem</h1>
<p>In the next image you can see the standard behavior of the MD5-function found.<br />
Most of them looks okay, but notice that the one from bombaydigital uses uppercase hex notation, and by using it for another round with MD5 it will go wrong.<br />
The one found on Stockoverflow clearly doesn&#8217;t use hex-notation. And the one from Spiration, lost a 0 (zero).</p>
<div id="attachment_101" class="wp-caption alignnone" style="width: 310px"><a href="http://m2tec.be/blog/wp-content/uploads/2010/02/single-md5.png" rel="lightbox[93]" title="single-md5"><img class="size-medium wp-image-101" title="single-md5" src="http://m2tec.be/blog/wp-content/uploads/2010/02/single-md5-300x140.png" alt="" width="300" height="140" /></a><p class="wp-caption-text">MD5 function output from different sites</p></div>
<p>With double MD5 you see the differences even faster, like shown in the next image:</p>
<div id="attachment_104" class="wp-caption alignnone" style="width: 310px"><a href="http://m2tec.be/blog/wp-content/uploads/2010/02/double-md5.png" rel="lightbox[93]" title="double-md5"><img class="size-medium wp-image-104" title="double-md5" src="http://m2tec.be/blog/wp-content/uploads/2010/02/double-md5-300x140.png" alt="" width="300" height="140" /></a><p class="wp-caption-text">differences seen by using double use of MD5 functions found for java</p></div>
<p>The first marked line, you see that Spiration&#8217;s MD5 is wrong, in the second marked line, you see Spirition&#8217;s MD5 is ok. So it&#8217;s not reliable.<br />
In the first and second marked lines you can see that dzone&#8217;s MD5  is ok, but the thirth and fourth are wrong. Also, not reliable.<br />
As noted by single MD5, StockOverflow is not hex and bombaydigital is uppercase, so both functions aren&#8217;t giving me the expected output.</p>
<h1>The right solution</h1>
<p>This leaves us with the one from twmacinta, clearly it&#8217;s working, but in code, I needed 779 lines (including comment)<br />
But it&#8217;s not really worth if it can be done in nearly 10 lines of code.</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">JAVA HEX MD5</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://m2tec.be/blog/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://m2tec.be/blog/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://m2tec.be/blog/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://m2tec.be/blog/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="java" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw1">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Astring+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">String</span></a> MD5<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Astring+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">String</span></a> md5<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">   <span class="kw1">try</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        java.<span class="me1">security</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amessagedigest+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Amessagedigest+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">MessageDigest</span></a> md <span class="sy0">=</span> java.<span class="me1">security</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amessagedigest+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Amessagedigest+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">MessageDigest</span></a>.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="st0">&quot;MD5&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="kw4">byte</span><span class="br0">&#91;</span><span class="br0">&#93;</span> array <span class="sy0">=</span> md.<span class="me1">digest</span><span class="br0">&#40;</span>md5.<span class="me1">getBytes</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Astringbuffer+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">StringBuffer</span></a> sb <span class="sy0">=</span> <span class="kw1">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Astringbuffer+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">StringBuffer</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> array.<span class="me1">length</span><span class="sy0">;</span> <span class="sy0">++</span>i<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">          sb.<span class="me1">append</span><span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Ainteger+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">Integer</span></a>.<span class="me1">toHexString</span><span class="br0">&#40;</span><span class="br0">&#40;</span>array<span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="sy0">&amp;</span> 0xFF<span class="br0">&#41;</span> <span class="sy0">|</span> 0x100<span class="br0">&#41;</span>.<span class="me1">substring</span><span class="br0">&#40;</span>1,3<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">       <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">return</span> sb.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">    <span class="br0">&#125;</span> <span class="kw1">catch</span> <span class="br0">&#40;</span>java.<span class="me1">security</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Anosuchalgorithmexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Anosuchalgorithmexception+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">NoSuchAlgorithmException</span></a> e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">return</span> <span class="kw2">null</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>So don&#8217;t just copy/paste everything you find by using google. Other sites (just like me) can be wrong, yes, we are also just people.</p>
]]></content:encoded>
			<wfw:commentRss>http://m2tec.be/blog/2010/02/03/java-md5-hex-0093/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

