diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 19f68b46..4aebd11f 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -2818,32 +2818,34 @@ namespace WebSocketSharp return; } - lock (_forState) { - if (!checkIfAvailable (true, false, false, true, out msg)) { - _logger.Error (msg); + if (!username.IsNullOrEmpty ()) { + if (username.Contains (':') || !username.IsText ()) { + _logger.Error ("'username' contains an invalid character."); error ("An error has occurred in setting the credentials.", null); return; } - if (username.IsNullOrEmpty ()) { - _logger.Warn ("The credentials are set back to the default."); - _credentials = null; - _preAuth = false; + if (!password.IsNullOrEmpty () && !password.IsText ()) { + _logger.Error ("'password' contains an invalid character."); + error ("An error has occurred in setting the credentials.", null); return; } + } - if (username.Contains (':') || !username.IsText ()) { - _logger.Error ("'username' contains an invalid character."); + lock (_forState) { + if (!checkIfAvailable (true, false, false, true, out msg)) { + _logger.Error (msg); error ("An error has occurred in setting the credentials.", null); return; } - if (!password.IsNullOrEmpty () && !password.IsText ()) { - _logger.Error ("'password' contains an invalid character."); - error ("An error has occurred in setting the credentials.", null); + if (username.IsNullOrEmpty ()) { + _logger.Warn ("The credentials are set back to the default."); + _credentials = null; + _preAuth = false; return; }