<?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>ForestMist &#187; ASP</title>
	<atom:link href="http://forestmist.org/tag/asp/feed/" rel="self" type="application/rss+xml" />
	<link>http://forestmist.org</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 03:17:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Add a password reset feature to Halogen eAppraisal</title>
		<link>http://forestmist.org/2010/04/add-a-password-reset-feature-to-halogen-eappraisal/</link>
		<comments>http://forestmist.org/2010/04/add-a-password-reset-feature-to-halogen-eappraisal/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 05:45:19 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[Encryption]]></category>

		<guid isPermaLink="false">http://forestmist.org/?p=1058</guid>
		<description><![CDATA[One really important feature missing from Halogen eAppraisal is the ability for users to reset their own passwords. Seems like such a basic feature but even their friendly support folks confirmed that there was no addon or plan to release the feature in a future version. Weird! No matter though, let&#8217;s make our own. Investigation I spent [...]]]></description>
			<content:encoded><![CDATA[<p>One really important feature missing from Halogen eAppraisal is the ability for users to reset their own passwords.</p>
<p>Seems like such a basic feature but even their friendly support folks confirmed that there was no addon or plan to release the feature in a future version. Weird!</p>
<p>No matter though, let&#8217;s make our own.</p>
<h2>Investigation</h2>
<p>I spent untold amounts of time clawing through unfamiliar Java code. A occasional scrap was enough to forge my determination but nothing really made sense yet. Too many files, too many directories but maybe if I just kept trying&#8230;</p>
<p><a href="http://www.youtube.com/watch?v=8HE9OQ4FnkQ">A-ha</a>!</p>
<p>Hidden deep within the lair of &lt;Tomcat&gt;\webapps\Halogen\WEB-INF\classes\com\halogensoftware\common\security\ is a file called &#8216;Utility.class&#8217;. Inside, a string that resembles the worst regular expression ever created.</p>
<p style="padding-left: 30px;">^a`Z{b1Y}c2X[d3W]e4V|f5U\g6T:h7S;i8R&#8221;j9Q&#8217;k0P&lt;l-O&gt;m=N?n~M,o!L.p@K/q#Jr$Is%Ht^Gu&amp;Fv*Ew(Dx)Cy_Bz+A</p>
<p>I was sure this string was used to encrypt the passwords stored in the database but I needed a way to confirm that so&#8230;</p>
<p>Using a test account I set the password to the number 1 which was encrypted as the letter Y. Password 11 became Y}. Password 111 became Y}c.</p>
<p>Ah, so simple!</p>
<p>If your password was the ^ symbol it would find it in the string above and then move right one space and choose the letter &#8220;a&#8221; as your encrypted password. If your password was ^^ then the the first encrypted character would be &#8220;a&#8221; again but the second one would shift two places to the right and store the ` symbol</p>
<p>Here are a few more example conversions.</p>
<ul>
<li>^^^ becomes a`Z</li>
<li>wT7w becomes (hi)</li>
<li>A+z becomes ^^^</li>
</ul>
<p>Notice that in the last example we&#8217;ve simply looped around once we hit the right side of the hash string.</p>
<p>Now that we know how it works let&#8217;s build our own utility in ASP that we can use to reset anyone&#8217;s password.</p>
<h2>The Solution</h2>
<p>Besides the obvious DSN string, you&#8217;ll want to carefully consider how you validate your users.</p>
<p>The setup I used at work talked to a Human Resources database and would validate no less than three pieces of information before even attempting a reset. I urge you dear reader to do the same.</p>
<pre class="brush: vb; title: ; notranslate">
sID = Request.Form(&quot;id&quot;)
sPassword = Request.Form(&quot;password&quot;)

Set oConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
oConn.Open &quot;DSN String for the Halogen eAppraisal Database&quot;

Set oRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
oRS.Open &quot;SELECT TOP 1 * FROM [view-user_info] WHERE username = '&quot; &amp; sID &amp; &quot;'&quot;, oConn, 0, 3 'adOpenForwardOnly, adLockOptimistic

If not oRS.EOF then
	sKeyCode = &quot;a`Z{b1Y}c2X[d3W]e4V|f5U\g6T:h7S;i8R&quot;&quot;j9Q'k0P&lt;l-O&gt;m=N?n~M,o!L.p@K/q#Jr$Is%Ht^Gu&amp;Fv*Ew(Dx)Cy_Bz+A&quot;
	sKeyCodeLength = Len(sKeyCode)
	x = 1
	sBadChar = 0
	Do until x &gt; Len(sPassword)
		sChar = Mid(sPassword, x, 1)

		If InStr(sKeyCode, sChar) then
			sKeyCodePos = InStr(sKeyCode, sChar) + x
			If sKeyCodePos &gt; sKeyCodeLength then
				'Need to loop around the beginning
				Do until sKeyCodePos &lt;= sKeyCodeLength
					sKeyCodePos = sKeyCodePos - sKeyCodeLength
				loop
			End If
			sEncodeChar = Mid(sKeyCode, sKeyCodePos, 1)
			sEncodePassword = sEncodePassword + sEncodeChar
		Else
			'Could not find a character in sKeyCode
			sBadChar = sBadChar + 1
		End If
		x = x + 1
	loop

	If sBadChar &gt; 0 then
		Response.Write &quot;&lt;p&gt;&lt;strong&gt;Unsupported characters were used to try to set the encrypted password. New password was not saved.&lt;/strong&gt;&lt;/p&gt;&quot;
	Else
		oRS(&quot;password&quot;) = sEncodePassword
		oRS(&quot;password_change_date&quot;) = NULL
		oRS.Update
		Response.Write &quot;&lt;p&gt;The password for your account &quot; &amp; sID &amp; &quot; has been reset.&lt;/p&gt;&quot;
	End If
Else
	Response.Write &quot;&lt;p&gt;&lt;strong&gt;A corresponding account for the user &quot; &amp; sID &amp; &quot; does not exist. Please contact support.&lt;/strong&gt;&lt;/p&gt;&quot;
End If

oRS.Close
oConn.Close
Set oRS = nothing
Set oConn = nothing
</pre>
<p>Questions welcome so feel free to comment below.</p>
<p>See ya later, space cowboy.</p>
]]></content:encoded>
			<wfw:commentRss>http://forestmist.org/2010/04/add-a-password-reset-feature-to-halogen-eappraisal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

