Mysql
 sql >> Base de données >  >> RDS >> Mysql

Simuler MySql OLD_PASSWORD dans .NET ou MS SQL ?

J'en ai trouvé un sur 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();
}