diff --git a/SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs b/SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs index 6a9646a44..fca8d21aa 100644 --- a/SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs +++ b/SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs @@ -137,6 +137,25 @@ public async Task BeginAuthSessionViaCredentialsAsync( A throw new InvalidOperationException( "The SteamClient instance must be connected." ); } + // Password limit. + const int MAX_PASSWORD_SIZE = 64; + if (!string.IsNullOrEmpty(details.Password) && details.Password.Length >= MAX_PASSWORD_SIZE) + { + DebugLog.WriteLine(nameof(SteamUser), $"Notice: password is longer than {MAX_PASSWORD_SIZE} characters."); + } + + // Password Unicode check. + if (details.Password != null) + { + for (var i = 0; i < details.Password.Length; i++) + { + if (details.Password[i] > 127) + { + throw new ArgumentException( "Password contains non standard ASCII characters." ); + } + } + } + // Encrypt the password var publicKey = await GetPasswordRSAPublicKeyAsync( details.Username! ).ConfigureAwait( false ); var rsaParameters = new RSAParameters diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs index f073dd837..ae9b2ef30 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs @@ -231,6 +231,25 @@ public void LogOn( LogOnDetails details ) throw new ArgumentException( "LogOn requires a username and password or access token to be set in 'details'." ); } + // Password limit. + const int MAX_PASSWORD_SIZE = 64; + if (!string.IsNullOrEmpty(details.Password) && details.Password.Length >= MAX_PASSWORD_SIZE) + { + DebugLog.WriteLine(nameof(SteamUser), $"Notice: password is longer than {MAX_PASSWORD_SIZE} characters."); + } + + // Password Unicode check. + if (details.Password != null) + { + for (var i = 0; i < details.Password.Length; i++) + { + if (details.Password[i] > 127) + { + throw new ArgumentException( "Password contains non standard ASCII characters." ); + } + } + } + if ( !this.Client.IsConnected ) { this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) );