Archive for the ‘Java’ Category

Howto implement MySQL’s OLD_PASSWORD() in Java

July 23rd, 2010 makii Comments off

Like most Software Engineers I don’t have the luxury to start with an greenfield strategy. Most times we know a good and viable solution to a problem, but cannot implement it due to restrictions which come with legacy systems and stuff out of our control.

Recently I had to migrate Newsletter subscribers to a newly created subscription system which uses an Oracle Database (I would have preferred PostgreSQL) rather than a MySQL, as the old system does.

Programmers are lazy, and as expected the developers of the old system used the OLD_PASSWORD(str) function from the database available to hash the password entered by the user. This is a very convenient way to protect the users’ login credentials, but rather bad when migrating to another system which has different or none implementations of this functionality. So what do we do? The options are:

  • Send every user a new password. Bad, we don’t want to harass them with our technical issues.
  • Force them to set a new password when they log in the next time. See above
  • Try to find a solution to validate the password against the old password hash.

As MySQL is widely used and a lot of data migration happens to and from, someone must have been run in this issue already, and most likely there is a solution to this problem in the net. And there is. I found a reimplementation of the OLD_PASSWORD() function in C# at (attention, german) and together with my coworker Maurice we ported it to Java, resulting in this piece of code:

public static String mysqlOldPassword(byte[] password) {
        int[] result = new int[2];
        int nr = 1345345333;
        int add = 7;
        int nr2 = 0x12345671;
        int tmp;

        int i;
        for (i = 0; i < password.length; i++) {
            if (password[i] == ' ' || password[i] == '\t')

            tmp = (int) password[i];
            nr ^= (((nr & 63) + add) * tmp) + (nr << 8);
            nr2 += (nr2 << 8) ^ nr;
            add += tmp;

        result[0] = nr & ((1 << 31) - 1);
        int val = ((1 << 31) - 1);
        result[1] = nr2 & val;
        String hash = String.format("%08x%08x",result[0],result[1]);
        return hash.toLowerCase();

I give no guarantee this will work in all cases. My IDE complains all over the place about possible integer overflows. The usage of Integer.toHexString()did not work either, as the resulting String is not padded up with zeroes.

Finally, some Unit Tests for the interested user:

    public void testOldPassword() throws Exception {
        final String expected = "0414ac6137ee1adc";
        byte[] bytes = "fooo".getBytes("UTF8");
        String foo = mysqlOldPassword(bytes);
        assertEquals(expected, foo);

    public void testOldPassword2() throws Exception {
        final String expected = "3fa0dce62ba931b5";
        byte[] bytes = "hastewas".getBytes("UTF8");
        String foo = mysqlOldPassword(bytes);
        assertEquals(expected, foo);

Have fun with it!

Categories: Java, Technology, Web Tags: , , , ,

Java – The Movie

June 27th, 2010 makii Comments off

For all you out there who code java like me :-)

And everyone else…

via @pommesbude

Update:Youtube seemingly has killed the video, but the original version is still available here.

Java is hot!!!

May 15th, 2009 123Laune Comments off

But we all knew it anyway…. ;-)


Categories: Java Tags:

Microsoft’s “Apple Tax”. WTF?

April 12th, 2009 makii Comments off

After Microsoft’s ad starring Jerry Seinfeld and Bill Gates, which was the first response to the well-known Get a Mac commercials, was kind of a flop, they recently started the Laptop Hunters series. Watching it is kind of funny. Mostly, for my part, because of the reactions of the people when they’re presented with the money for their computer-to-be.

Apart from that, the Company From Redmond commissioned, or sponsored, as they call it, an analysis from Endpoint Technologies Associates, which should transparently describe the “Apple Tax”. At the first glance the form (filled out by hand, as it seems) looks pretty convincing, stating an overall saving of more than 3300 bucks when you buy a PC instead of a Mac. Is that really true?

Ina Fried from Cnet took a closer look at the findings and is not convinced. The report states no additional license fees for the Windows systems despite the OEM licenses included in the hardware price. Where do they get there Software from? Do they use OpenOffice? Do they use copies from their friends illegally? Why do they list the (totally optional) MobileMe account? This account on it’s own bills for about $750 in the five years. I know only one person who uses MobileMe and he will discontinue it.

Sure, Apple hardware is more expansive in comparison to PC hardware, that’s true. But as the Windows Experience Blog states correctly, it’s not only about cost, but about value. I’m an Apple user for about a half year now and I think I get a lot more value for my money than for my previous laptops, which were PC systems. In germany we have two words to describe this difference. The word which describes a possibly good deal is “günstig”, which translates well to cheap as in low priced. “billig” also means cheap, but more in a kind of this product’s kinda crappy way. A lot of PC hardware in the past was “billig”, and the present one often still is. The hardware of these systems does not fit together well, the cheap ones still have a ridiculously low resolution (I will never work willingly on anything below 1400×900 on 14″ or 15″ screens). The chassis stability of Macs might be reached by Thinkpads, but the Design I think is still leading, though it is quite simply.

To the software. I had installed Windows on my previous PC systems, and I even have a BootCamp installation with Windows XP on it on my Mac. I boot it two or three times a month to play games which unfortunately are not available for OSX (Assasins Creed and Fallout 3) and don’t work with Crossover Games properly. That’s all I use it for, and, hell, that’s all I need it for. The last five years I solely worked on Unix- and Linux- based systems. And I like it. Instead of clicking around endlessly in the explorer or the System Control I have a powerful shell (zsh or bash) and I can do everything on the fast lane. For the direct functions of the operating system the clicking point is also valid for OSX. But the simple gestures on the trackpad, or the Expose configuration is so addictive I tried to switch workspaces on my Linux workstation in the office by moving the mouse pointer to the upper right corner only two days after I bought my first Mac (yeah, I know. This might become a problem someday).

The important part for me is: Mac OSX, while shiny and colorful, has a Unix foundation, which is (IMO, even if not open source), a good thing. No ugly Cygwin necessary. There is MacPorts. There is Fink. Lots of stuff I need for everyday life. And the parts which come with OSX UI are most natural and intuitive.

To the point. I like Apple Hardware and Software, because

  • It looks kinda cool. This sure is one major point why Apple is so successful.
  • The hardware is sturdy.
  • The software fits my needs.
  • There is not that much malware, spyware and other bad stuff for OSX, if any.
  • There is a usable Unix environment underneath all that glamour.
  • I am not ridicuously accurate about free software licenses, though I like and respect free software in general.

I have stopped looking into Microsoft’s operating systems since Windows 2000. As mentioned before I’ve run XP on my Samsung X20 and MacBook Pro for gaming only. This was good as I can tell you now. Having started at a new Job I need to speak with a funny Exchange Server from Redmond Industries which I could not get up and running with anything I tried with Evolution, so I continued using the pre-installed Vista. It looks good enough for now, but still is a plain continuation of the user interface concepts from Windows 95. I still have to use the embedded context menue to create a new folder. It still comes with 2 tons of funny software preinstalled which needs to be cleaned out before you can somehow work with the system. Every tool which should bring me some sane Virtual Desktop support is either broken somehow, or is totally cumbersome to use. I think this will be my next desktop wallpaper…

I wish I had a Mac.

But this would not help either, this mail setup does not work for Entourage either.

So I’m (again, for once) stuck with Windows and no light at the end of the tunnel. I think I’ll, if time allowes, play a bit more with an Ubuntu in some virtual box setup and try to get Mail access up and running with Linux. Till then I need to work around with the most sane environment on windows, which still is Cygwin, which offers a sane xterm, zsh/bash, screen and some other utilities which I never want to miss.

Comming back to the topic of this post: There sure is some kind of “Apple Tax” if you want to call it that. BUT I really really doubt that it is so high as described in the Microsoft-paid paper. My opinion is that users get more value for a higher price. Some of the added value is purely aestetic, another is less pain in the ass, as they don’t bloat up their registry with a ton of funny entries for installing software they simply want to try, viruses, malware, The Search For The Driver(tm) and other stuff. The whole software suit from Apple is much more integrated and more simple to use. Every user has to decide whether they think it’s worth the price for them. If (probably) crappy hardware with Windows works for them – who am I to judge?

Despite that, the Get a Mac ads from Apple are more conciliabe, meaning they acknowledge the strengths of the PC to some degree, even if in a comical way. Laptop Hunters is a more offensive and absolutistic approach to compare the two systems, telling the customers Apple is stealing money from them. That’s business, OK, but it’s totally unfair.

Categories: Java, Mac, Windows Tags: , ,

Patterns Reloaded: The other Singleton

November 19th, 2008 123Laune Comments off


A Singleton both PHP- and JEE-DevGuys should like ;-)

Categories: Common, Java, Technology, funny Tags:

parallelization + array = ParallelArray

October 17th, 2008 AVC Comments off

The idea is that a ParallelArray represents a collection of structurally similar data items, and you use the methods on ParallelArray to create a description of how you want to slice and dice the data. You then use the description to actually execute the array operations, which uses the fork-join framework under the hood, in parallel…This idea coming in JDK 7 :)

In fact, here are some operations supported by ParallelArray:

  • Filtering: selecting a subset of the elements
  • Mapping: convert selected elements to another form
  • Replacement: create a new ParallelArray derived from the original
  • Aggregation: combine all values into a single value
  • Application: perform an action for each selected element

- avc

Categories: 16ms, Coding, Common, Java, Technology Tags:

The best Java Exception ever

October 10th, 2008 makii Comments off

A lot of thanks to Code To Joy for the best Java Exception I ever saw: JavaDoc of CME

Categories: Coding, Java, funny Tags:

String literals

June 2nd, 2008 makii Comments off

When coding in Java, I usually try to avoid string literals in the code, especiall when they reference other software components like templates, which are filled with values in arbitrary places throughout the code. This is what I found in a project which we’re going to insource soon:

#-[ user@host ]- ~/work/project/trunk
#-[0]-> find . -type f -name "*.java" -exec grep -r "\"salutation2\"" {} \; | wc -l
#-[ host@host ]- ~/work/project/trunk

No comment.

Categories: Coding, Java Tags: ,

My oh my what have we here…

April 22nd, 2008 derlanders Comments off

Did you ever get scared about modern Software being all too intelligent, that it would finally take control and such? Don’t be.


Categories: Common, Java, Technology, Work Tags:

Funny things when building web applications…

April 3rd, 2008 makii Comments off

When you build a web application using maven2, there are funny log messages in the output, if you care see them:

[INFO] [war:war]
[INFO] Packaging webapp
[INFO] Assembling webapp[commodities.view] in [C:\code\commodities.view\target\commodities.view-0.1-SNAPSHOT]
[INFO] Processing war project

Whom is this maven thingy going to attack???

© derlanders

Categories: Java, Work, office Tags: