HashCode is different in WebService and WebService under Azure

Answered HashCode is different in WebService and WebService under Azure

  • Thursday, May 17, 2012 11:31 PM
     
     

    I'm migrating our database from MySQL to SQL Azure and the files and services hosted with another hosting provider to Windows Azure, we had migrated the databases and the Web Service without problems, but we are saving the password of our users as hashCode, and the hashCode varies from my previous Web Service to my new Web Service under Windows Azure, for example the hashCode of the character "1" is -842352753 consuming the Web Service without Windows Azure, and running under Windows Azure the Web Service return the hashCode 372029325, so we cannot validate our users.

    Do you know a solution to solve this issue?

    I'm not doing anything with SQL Azure yet, I'm testing the Web Services getting the hashCode of a string with a method like this:

    string getData(string s)

    {

             return s.GetHashCode.ToString();

    }

    And I was consuming the Web Service in my client calling the method in the service with this code:

    ServiceClient.getData("1");

    Then the Web Service get me the hashCode of my string, in this case "1", I didn't use databases yet.

    I guess that the variation of the hashCode is due of the version of Framework or the Architecture of the OS, but I don't know if the variation is due to the Web Service is running under Windows Azure, maybe this is  happening, because the hashCode returned varies if I run the Web Service Local or I run the Web Service under Windows Azure, both are running in my Laptop.

    Thanks and greetings.


    Adán Carrasco

All Replies

  • Friday, May 18, 2012 6:48 AM
    Moderator
     
     

    Hi,

    You mean you're trying to use GetHashCode method to validate users, right? From this link, please check :

    http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx

    The default implementation of the GetHashCode method does not guarantee unique return values for different objects. Furthermore, the .NET Framework does not guarantee the default implementation of the GetHashCode method, and the value it returns will be the same between different versions of the .NET Framework. Consequently, the default implementation of this method must not be used as a unique object identifier for hashing purposes.

    The different .NET Framework can not guarantee default implementation of this method will return the same value, so i think this is not the recommended way to do that with authentication, unless you can implement this method by yourself.

    I suggest you use other hash encrypt method, such as SHA-2 or MD5:

    http://dotnetrush.blogspot.com/2007/04/c-sha-2-cryptography-sha-256-sha-384.html

    http://www.techlicity.com/blog/dotnet-hash-algorithms.html

    Hope this helps.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

  • Friday, May 18, 2012 7:55 PM
     
     

    Hi Arwind.

    The problem is that I already have users registered with their password as hashcode and I need migrate to other platform in this case Windows Azure. Is there a way to get the hashCode as I have saved provided by my current Framework?

    Thanks.


    Adán Carrasco

  • Monday, May 21, 2012 5:03 AM
    Moderator
     
     Answered

    Hi,

    I suppose no, the better solution is update the encryption module of your application. And you need create a tool to change the user passwords (stored in database) to new.

    Hope this helps. 


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    • Marked As Answer by Adán.Carrasco Wednesday, May 23, 2012 5:07 PM
    •  
  • Wednesday, May 23, 2012 5:08 PM
     
     

    Hi,

    Ok, then I'll update my encryption module.

    Thanks and greetings.


    Adán Carrasco