Skip to content

Commit 2aea924

Browse files
committed
Change parameter name for clarity and update documentation.
Signed-off-by: Bradley Grainger <[email protected]>
1 parent 03d179e commit 2aea924

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ private bool ValidateFingerprint(byte[]? validationHash, ReadOnlySpan<byte> chal
624624
switch (m_pluginName)
625625
{
626626
case "mysql_native_password":
627-
passwordHashResult = AuthenticationUtility.HashPassword([], password, false);
627+
passwordHashResult = AuthenticationUtility.HashPassword([], password, onlyHashPassword: true);
628628
break;
629629

630630
case "client_ed25519":

src/MySqlConnector/Protocol/Serialization/AuthenticationUtility.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@ public static byte[] GetNullTerminatedPasswordBytes(string password)
2525
}
2626

2727
public static byte[] CreateAuthenticationResponse(ReadOnlySpan<byte> challenge, string password) =>
28-
string.IsNullOrEmpty(password) ? [] : HashPassword(challenge, password, true);
28+
string.IsNullOrEmpty(password) ? [] : HashPassword(challenge, password, false);
2929

3030
/// <summary>
3131
/// Hashes a password with the "Secure Password Authentication" method.
3232
/// </summary>
3333
/// <param name="challenge">The 20-byte random challenge (from the "auth-plugin-data" in the initial handshake).</param>
3434
/// <param name="password">The password to hash.</param>
35-
/// <param name="withXor">must xor results.</param>
35+
/// <param name="onlyHashPassword">If true, <paramref name="challenge"/> is ignored and only the twice-hashed password
36+
/// is returned, instead of performing the full "secure password authentication" algorithm that XORs the hashed password against
37+
/// a hash derived from the challenge.</param>
3638
/// <returns>A 20-byte password hash.</returns>
3739
/// <remarks>See <a href="https://dev.mysql.com/doc/internals/en/secure-password-authentication.html">Secure Password Authentication</a>.</remarks>
3840
#if NET5_0_OR_GREATER
3941
[SkipLocalsInit]
4042
#endif
41-
public static byte[] HashPassword(ReadOnlySpan<byte> challenge, string password, bool withXor)
43+
public static byte[] HashPassword(ReadOnlySpan<byte> challenge, string password, bool onlyHashPassword)
4244
{
4345
#if !NET5_0_OR_GREATER
4446
using var sha1 = SHA1.Create();
@@ -56,7 +58,7 @@ public static byte[] HashPassword(ReadOnlySpan<byte> challenge, string password,
5658
sha1.TryComputeHash(passwordBytes, hashedPassword, out _);
5759
sha1.TryComputeHash(hashedPassword, combined[20..], out _);
5860
#endif
59-
if (!withXor)
61+
if (onlyHashPassword)
6062
return combined[20..].ToArray();
6163

6264
challenge[..20].CopyTo(combined);

0 commit comments

Comments
 (0)