public async Task AuthenticationTest() { Message.Initialize(); NetworkServer.Start(5000, (Sender, Username, Password) => (Username == "User2" && Password == "P@ssw1rd!", "")); NetworkClient TestClient = new NetworkClient("localhost", 5000); (bool Accepted, string Reason)AuthenticationResult1 = await TestClient.Authenticate("User", "P@ssw0rd!"); (bool Accepted, string Reason)AuthenticationResult2 = await TestClient.Authenticate("User2", "P@ssw0rd!"); (bool Accepted, string Reason)AuthenticationResult3 = await TestClient.Authenticate("User", "P@ssw1rd!"); (bool Accepted, string Reason)AuthenticationResult4 = await TestClient.Authenticate("User2", "P@ssw1rd!"); bool EncryptionEnabled = await TestClient.InitializeEncryption(); (bool Accepted, string Reason)AuthenticationResult5 = await TestClient.Authenticate("User", "P@ssw0rd!"); (bool Accepted, string Reason)AuthenticationResult6 = await TestClient.Authenticate("User2", "P@ssw0rd!"); (bool Accepted, string Reason)AuthenticationResult7 = await TestClient.Authenticate("User", "P@ssw1rd!"); (bool Accepted, string Reason)AuthenticationResult8 = await TestClient.Authenticate("User2", "P@ssw1rd!"); NetworkServer.Stop(); TestClient.Dispose(); Assert.IsFalse(AuthenticationResult1.Accepted); Assert.IsFalse(AuthenticationResult2.Accepted); Assert.IsFalse(AuthenticationResult3.Accepted); Assert.IsFalse(AuthenticationResult4.Accepted); Assert.IsFalse(AuthenticationResult5.Accepted); Assert.IsFalse(AuthenticationResult6.Accepted); Assert.IsFalse(AuthenticationResult7.Accepted); Assert.IsTrue(AuthenticationResult8.Accepted); Assert.IsTrue(TestClient.IsLocalClientAuthenticated); }
private IEnumerator Login(string username, string password) { inputUsername.readOnly = true; inputPassword.readOnly = true; while (!networkClient.IsConnected) { networkClient.Connect(); yield return(null); } if (!networkClient.IsAuthenticated) { networkClient.Authenticate(username, password); yield return(null); } inputUsername.readOnly = false; inputPassword.readOnly = false; gameObject.SetActive(false); }