Oracle 5.0 Reference Manual page 1926

Table of Contents

Advertisement

Debug.WriteLine("Calling MySqlNativePasswordPlugin2.GetPassword");
return Get411Password(Settings.Password, AuthData);
}
/// <summary>
/// Returns a byte array containing the proper encryption of the
/// given password/seed according to the new 4.1.1 authentication scheme.
/// </summary>
/// <param name="password"></param>
/// <param name="seed"></param>
/// <returns></returns>
private byte[] Get411Password(string password, byte[] seedBytes)
{
// if we have no password, then we just return 1 zero byte
if (password.Length == 0) return new byte[1];
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] firstHash = sha.ComputeHash(Encoding.Default.GetBytes(password));
byte[] secondHash = sha.ComputeHash(firstHash);
byte[] input = new byte[seedBytes.Length + secondHash.Length];
Array.Copy(seedBytes, 0, input, 0, seedBytes.Length);
Array.Copy(secondHash, 0, input, seedBytes.Length, secondHash.Length);
byte[] thirdHash = sha.ComputeHash(input);
byte[] finalHash = new byte[thirdHash.Length + 1];
finalHash[0] = 0x14;
Array.Copy(thirdHash, 0, finalHash, 1, thirdHash.Length);
for (int i = 1; i < finalHash.Length; i++)
return finalHash;
}
}
}
4. Notice that the plugin implementation just overrides GetPassword, and provides an
implementation to encrypt the password using the 4.1 protocol. We also put the following line in the
GetPassword
Debug.WriteLine("Calling MySqlNativePasswordPlugin2.GetPassword");
to provide confirmation that the plugin was effectively used. (You could also put a breakpoint on
that method.)
5. Enable the new plugin in the configuration file:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="MySQL" type="MySql.Data.MySqlClient.MySqlConfiguration,
MySql.Data"/>
</configSections>
<MySQL>
<AuthenticationPlugins>
<add name="mysql_native_password"
type="AuthPluginTest.MySqlNativePasswordPlugin2, AuthPluginTest"></add>
</AuthenticationPlugins>
</MySQL>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup></configuration>
6. Run the application. In Visual Studio, you will see the message
MySqlNativePasswordPlugin2.GetPassword
7. Continue enhancing the authentication logic, overriding more methods if you required.
20.2.5.7. Using Connector/Net with Table Caching
Connector/Net Programming
finalHash[i] = (byte)(finalHash[i] ^ firstHash[i - 1]);
body:
in the debug window.
1906
Calling

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents