@@ -25,20 +25,22 @@ public static byte[] GetNullTerminatedPasswordBytes(string password)
25
25
}
26
26
27
27
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 ) ;
29
29
30
30
/// <summary>
31
31
/// Hashes a password with the "Secure Password Authentication" method.
32
32
/// </summary>
33
33
/// <param name="challenge">The 20-byte random challenge (from the "auth-plugin-data" in the initial handshake).</param>
34
34
/// <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>
36
38
/// <returns>A 20-byte password hash.</returns>
37
39
/// <remarks>See <a href="https://dev.mysql.com/doc/internals/en/secure-password-authentication.html">Secure Password Authentication</a>.</remarks>
38
40
#if NET5_0_OR_GREATER
39
41
[ SkipLocalsInit ]
40
42
#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 )
42
44
{
43
45
#if ! NET5_0_OR_GREATER
44
46
using var sha1 = SHA1 . Create ( ) ;
@@ -56,7 +58,7 @@ public static byte[] HashPassword(ReadOnlySpan<byte> challenge, string password,
56
58
sha1 . TryComputeHash ( passwordBytes , hashedPassword , out _ ) ;
57
59
sha1 . TryComputeHash ( hashedPassword , combined [ 20 ..] , out _ ) ;
58
60
#endif
59
- if ( ! withXor )
61
+ if ( onlyHashPassword )
60
62
return combined [ 20 ..] . ToArray ( ) ;
61
63
62
64
challenge [ ..20 ] . CopyTo ( combined ) ;
0 commit comments