Skip to content

Commit e700ecb

Browse files
committed
Remove trim. Add Unicode check.
Notify password length is greater 64. Throw an error since Steam does reject non standard ASCII characters.
1 parent 8e13286 commit e700ecb

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs

+17-6
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,27 @@ public async Task<CredentialsAuthSession> BeginAuthSessionViaCredentialsAsync( A
137137
throw new InvalidOperationException( "The SteamClient instance must be connected." );
138138
}
139139

140-
// Encrypt the password
141-
var publicKey = await GetPasswordRSAPublicKeyAsync( details.Username! ).ConfigureAwait( false );
140+
// Password limit.
141+
const int MAX_PASSWORD_SIZE = 64;
142+
if (!string.IsNullOrEmpty(details.Password) && details.Password.Length >= MAX_PASSWORD_SIZE)
143+
{
144+
DebugLog.WriteLine(nameof(SteamUser), $"Notice: password is longer than {MAX_PASSWORD_SIZE} characters.");
145+
}
142146

143-
// Password limit is 64. If it's longer, trim it.
144-
if (!string.IsNullOrEmpty(details.Password) && details.Password.Length > 64)
147+
// Password Unicode check.
148+
if (details.Password != null)
145149
{
146-
DebugLog.WriteLine(nameof(SteamAuthentication), "Notice: password is longer than 64 characters and will be trimmed.");
147-
details.Password = details.Password.Substring(0, 64);
150+
for (var i = 0; i < details.Password.Length; i++)
151+
{
152+
if (details.Password[i] > 127)
153+
{
154+
throw new ArgumentException( "Password contains non standard ASCII characters." );
155+
}
156+
}
148157
}
149158

159+
// Encrypt the password
160+
var publicKey = await GetPasswordRSAPublicKeyAsync( details.Username! ).ConfigureAwait( false );
150161
var rsaParameters = new RSAParameters
151162
{
152163
Modulus = Utils.DecodeHexString( publicKey.publickey_mod ),

SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs

+19
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,25 @@ public void LogOn( LogOnDetails details )
231231
throw new ArgumentException( "LogOn requires a username and password or access token to be set in 'details'." );
232232
}
233233

234+
// Password limit.
235+
const int MAX_PASSWORD_SIZE = 64;
236+
if (!string.IsNullOrEmpty(details.Password) && details.Password.Length >= MAX_PASSWORD_SIZE)
237+
{
238+
DebugLog.WriteLine(nameof(SteamUser), $"Notice: password is longer than {MAX_PASSWORD_SIZE} characters.");
239+
}
240+
241+
// Password Unicode check.
242+
if (details.Password != null)
243+
{
244+
for (var i = 0; i < details.Password.Length; i++)
245+
{
246+
if (details.Password[i] > 127)
247+
{
248+
throw new ArgumentException( "Password contains non standard ASCII characters." );
249+
}
250+
}
251+
}
252+
234253
if ( !this.Client.IsConnected )
235254
{
236255
this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) );

0 commit comments

Comments
 (0)