Simulating MySql OLD_PASSWORD in .NET or MS SQL?

前端 未结 2 1220
心在旅途
心在旅途 2021-01-22 21:43

I have started a new project in .NET which uses some old system\'s datababase in MySql. The data stored in mysql is periodicaly transfered to MS Sql on which our system works. I

相关标签:
2条回答
  • 2021-01-22 22:26

    Here is a Perl module that emulates MySQL's password() function for both 4.0 and prior (which is now OLD_PASSWORD() function) and 4.1 and higher.

    While I realize that it's not .NET :-) that's the only piece of code (besides MySQL source)I found when I was looking for this, although I needed Java implementation. It worked for me and helped with migration - perhaps you'll be able to port it to .NET or run it as external process.

    0 讨论(0)
  • 2021-01-22 22:48

    I found one at http://www.yourhelpcenter.de/2009/06/mysql-alten-md5-hash-in-c-berechnen-16-stellig/

    public static string mysql_old_password(string sPassword)
    {
        UInt32[] result = new UInt32[2];
        bool bDebug = false;
        UInt32 nr = (UInt32)1345345333, add = (UInt32)7, nr2 = (UInt32)0x12345671;
        UInt32 tmp;
    
        char [] password = sPassword.ToCharArray();
        int i;
    
        for (i = 0; i < sPassword.Length; i++)
        {
            if (password[i] == ' ' || password[i] == '\t')
                continue;
    
            tmp = (UInt32)password[i];
            nr ^= (((nr & 63) + add) * tmp) + (nr << 8);
            nr2 += (nr2 << 8 ) ^ nr;
            add += tmp;
        }
    
        result[0] = nr & (((UInt32)1 << 31) - (UInt32)1);
        UInt32 val = (((UInt32)1 << 31) - (UInt32)1);
        result[1] = nr2 & val;
        string hash = String.Format("{0:X}{1:X}", result[0], result[1]);
        return hash.ToLower();
    }
    
    0 讨论(0)
提交回复
热议问题