Apr 15 2010

Add a password reset feature to Halogen eAppraisal

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’s make our own.

Investigation

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…

A-ha!

Hidden deep within the lair of <Tomcat>\webapps\Halogen\WEB-INF\classes\com\halogensoftware\common\security\ is a file called ‘Utility.class’. Inside, a string that resembles the worst regular expression ever created.

^a`Z{b1Y}c2X[d3W]e4V|f5U\g6T:h7S;i8R”j9Q’k0P<l-O>m=N?n~M,o!L.p@K/q#Jr$Is%Ht^Gu&Fv*Ew(Dx)Cy_Bz+A

I was sure this string was used to encrypt the passwords stored in the database but I needed a way to confirm that so…

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.

Ah, so simple!

If your password was the ^ symbol it would find it in the string above and then move right one space and choose the letter “a” as your encrypted password. If your password was ^^ then the the first encrypted character would be “a” again but the second one would shift two places to the right and store the ` symbol

Here are a few more example conversions.

  • ^^^ becomes a`Z
  • wT7w becomes (hi)
  • A+z becomes ^^^

Notice that in the last example we’ve simply looped around once we hit the right side of the hash string.

Now that we know how it works let’s build our own utility in ASP that we can use to reset anyone’s password.

The Solution

Besides the obvious DSN string, you’ll want to carefully consider how you validate your users.

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.

sID = Request.Form("id")
sPassword = Request.Form("password")

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

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

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

		If InStr(sKeyCode, sChar) then
			sKeyCodePos = InStr(sKeyCode, sChar) + x
			If sKeyCodePos > sKeyCodeLength then
				'Need to loop around the beginning
				Do until sKeyCodePos <= 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 > 0 then
		Response.Write "<p><strong>Unsupported characters were used to try to set the encrypted password. New password was not saved.</strong></p>"
	Else
		oRS("password") = sEncodePassword
		oRS("password_change_date") = NULL
		oRS.Update
		Response.Write "<p>The password for your account " & sID & " has been reset.</p>"
	End If
Else
	Response.Write "<p><strong>A corresponding account for the user " & sID & " does not exist. Please contact support.</strong></p>"
End If

oRS.Close
oConn.Close
Set oRS = nothing
Set oConn = nothing

Questions welcome so feel free to comment below.

See ya later, space cowboy.


Mar 3 2010

Disable right clicking on images only

There are few instances where disabling someone’s context menu is appropriate. In most cases it’s unnecessary and can even lead to infuriating your visitors.

Here are some ways to target all the image elements on a page while leaving the rest of the hypertext in peace.

JavaScript

Lightweight, no framework required and works well in IE 6, 7, 8, Chrome, FireFox and Safari. Demo »

document.oncontextmenu = context_menu;

function context_menu(e) {
if (!e) var e = window.event;
	var eTarget = (window.event) ? e.srcElement : e.target;

	if (eTarget.nodeName == "IMG") {
		//context menu attempt on top of an image element
		return false;
	}
}

jQuery

Perhaps the prettiest code of the three. Demo »

$(document).ready(function(){
	$(document).bind("contextmenu",function(e){
		if(e.target.nodeName == 'IMG'){
			//context menu attempt on top of an image element
			return false;
		}
	});
});

MooTools

Moo… Demo »

window.addEvent('domready', function() {
	$(document.body).addEvent('contextmenu', function(e) {
		if(e.target.nodeName == 'IMG') {
			//context menu attempt on top of an image element
			return false;
		}
	});
});

Final Thoughts

With a bit more code you can target specific IDs, class names or any number of elemental combinations. Doing so will limit your context menu friendly fire and keep both you and your users in a happy balance.

Cheers!


Feb 21 2010

Mass Effect 2 Soundtrack

Tali'Zorah knows that even in the future, corded headphones are the way to go.

I really enjoyed Mass Effect 2, so much so that I like to imagine talking to people with a choice selector near the bottom of my vision. I usually choose paragon options but I know the usefulness of a well placed renegade response. Be careful with the interrupts though!

Like many good games, I find myself drawn to the soundtrack as a way of reliving our times together. I went searching for it but unfortunately they only released it in MP3 and M4A formats so far.

Call me a snob but I think our future should be filled with upgrades and that means something better than or equal to the sound quality of a Compact Disc.

No worries though because with a bit of patience you too can…

Make your own Mass Effect 2 Soundtrack

These instructions assume you are using the PC version of the game.

Epilogue

Now you can enjoy 508 pieces of Ogg Vorbis encoded music while you wait for EA to release a proper Compact Disc.

Oh and special thanks to Extirpator for the original instructions on how to accomplish this.