sql >> Base de Datos >  >> RDS >> Mysql

¿Simulación de MySql OLD_PASSWORD en .NET o MS SQL?

Encontré uno en 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();
}