My unity login with Firebase is not working - c#

My register user is working perfectly, however when i try to log a user in i do not get any kind of message, successful login or failed login. I am trying to log my user in then move to my logged in screen. If anyone is able to see what it is i am doing wrong i would be very thankful!
I will provided my code below.
Thank you for your help!
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Text.RegularExpressions;
using UnityEngine.SceneManagement;
using Firebase;
using Firebase.Auth;
public class Login : MonoBehaviour {
public GameObject email;
public GameObject password;
private string Email;
private string Password;
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
void Update () {
if (email.GetComponent<InputField>().isFocused){
password.GetComponent<InputField>().Select();
}
if (Password != ""&&Password != ""){
LoginButton();
}
Email = email.GetComponent<InputField>().text;
Password = password.GetComponent<InputField>().text;
}
public void LoginButton()
{
auth.SignInWithEmailAndPasswordAsync(Email, Password).ContinueWith(task => {
if (task.IsCanceled) {
Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted) {
Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
SceneManager.LoadScene("LoginScreen");
});
}
}

Replace ContinueWith with ContinueWithOnMainThread, I think you should be good. If not, make sure you've enabled email sign in in the Firebase console.
I suspect that everything's working as expected, but because you're using ContinueWith your SceneManager logic is happening off of the main thread. In the best case scenario, this just won't work. In the worst case, you might see a crash.
See my article on threading in Unity and my video on Authentication for more information.

Related

Why doesn't Google Play Game authorization work in Unity?

I did everything right, I specified SHA1 in the Google API, Linked it all to Google Console, inserted resources and Web Client ID into Unity, but every time I try to log in, it writes "Canceled".
In LogCat I don't get errors, there are only:
*** [Play Games Plugin 0.11.01] 02.18.23 ERROR: Returning an error code
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
Google Play services out of date for iae.perfectray.dogs. Reqires 21300000 but found 212621032
Here is the authorization code:
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Auth : MonoBehaviour
{
// Start is called before the first frame update
public Text text;
void Start()
{
PlayGamesPlatform.Activate();
PlayGamesPlatform.DebugLogEnabled = true;
}
public void Authh()
{
PlayGamesPlatform.Instance.Authenticate(ProccessAuth);
}
internal void ProccessAuth(SignInStatus status)
{
if(status == SignInStatus.Success)
{
text.text = "Status: Succesfull";
}
else
{
text.text = "Status: " + status;
}
}
I've already tried everything, nothing works(

Index was outside the bounds of the array. Login+<LoginPlayer>d__4.MoveNext () (at Assets/Login.cs:29)

I'm building a system in Unity that takes a register and login menu connected to a MySQL database through PHPMyAdmin, has users log in, then allows them to choose between playing two games. I've been getting this error since I linked the games and I can't figure out how to fix it. The register works fine, but it won't allow for log in.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Login : MonoBehaviour
{
public TMP_InputField nameField;
public TMP_InputField passwordField;
public Button submitButton;
public void CallLogin()
{
StartCoroutine(LoginPlayer());
}
IEnumerator LoginPlayer()
{
WWWForm form = new WWWForm();
form.AddField("name", nameField.text);
form.AddField("password", passwordField.text);
WWW www = new WWW("http://localhost/sqlconnect/login.php", form);
yield return www;
if (www.text[0] == '0')
{
dbmanager.username = nameField.text;
dbmanager.score = int.Parse(www.text.Split('\t')[1]);
UnityEngine.SceneManagement.SceneManager.LoadScene(0);
}
else
{
Debug.Log("User Login failed. Error #" + www.text);
}
}
public void VerifyInputs()
{
submitButton.interactable = (nameField.text.Length >= 8 && passwordField.text.Length >= 8);
}
}
I've been trying to figure out what happened for hours and need some extra insight, can anyone please help?

Applitools + Specflow+ Selenium + C#

I'm asking for help, I'm already desperate.
I made a simple test script with Gherkin and generated the steps. I want to integrate Applitools into this process, that is, to use eyes.Check() method. But no matter how hard I try, every time I initialize the eyes object, I get the following error: Method not found: "Applitools.BatchInfo Applitools.IEyesBase.get_Batch().
Examples on applitools.com don't fit me, because the same Ruby implementation doesn't work for me, and the C# example doesn't involve using Gherkin.
My scenario:
#Default.Target.Environment:Edu
Feature: LoginScenario
#INWK.LP.C0002
Scenario: L001_Login
When I open Web Site
And I login as user my_email#edu.hse.ru with pass 12345678
Then I close browser
My steps:
using System.Drawing;
using Applitools;
using Applitools.Selenium;
using Lms.Helpers;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using TechTalk.SpecFlow;
using NUnit.Framework;
using Configuration = Applitools.Selenium.Configuration;
namespace Lms.Steps
{
[TestFixture]
[Binding]
public class LoginInLmsSteps
{
private IWebDriver driver;
private LoginHelper loginHelper;
private Eyes eyes;
private EyesRunner runner;
private string Url => "https://lms.hse.ru/";
[Before]
[SetUp]
public void BeforeEach()
{
Configuration config = new Configuration();
config.SetApiKey("my_key");
config.SetBatch(new BatchInfo("LMS Batch"));
config.AddBrowser(800, 600, BrowserType.CHROME);
runner = new ClassicRunner();
eyes = new Eyes(runner);
eyes.SetConfiguration(config);
}
[When(#"I open Web Site")]
public void WhenIOpenWebSite()
{
driver = new ChromeDriver();
driver.Url = Url;
}
[When(#"I login as user (.*) with pass (.*)")]
public void WhenILoginAsUserWithPass(string username, string password)
{
eyes.Open(driver, "LMS", "Login test", new Size(800, 600));
eyes.CheckWindow("Login Page");
loginHelper.Login(username, password);
eyes.CloseAsync();
}
[Then(#"I close browser")]
public void ThenICloseBrowser()
{
driver.Quit();
driver = null;
}
[TearDown]
public void AfterEach()
{
// If the test was aborted before eyes.close was called, ends the test as aborted.
eyes.AbortIfNotClosed();
//Wait and collect all test results
TestResultsSummary allTestResults = runner.GetAllTestResults();
}
}
}
That is, I catch the error already at the setup stage
I would be grateful for any help!

Apps not running on different machines

I have this code:
using System;
using System.IO;
using System.Net;
using System.Net.Mail;
namespace Nameddd
{
class Program
{
static void Main(string[] args)
{
Hosts();
Console.WriteLine("Loading..");
Console.WriteLine("Your computer is not supported");
Console.ReadKey();
}
static void Hosts()
{
{
using (StreamWriter w = File.AppendText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts")))
{
w.WriteLine("SOME_IP domain.com");
}
}
This program is working for me but apparently not on every system. I used VS 2015 community on Windows 10. On another computer my friend (with windows 7) - also working.
But for someone with Windows 10 it is not working. Application is not running, "loading cursor" - that's it. If I'm trying to delete the .exe it shows a message box with text like "process already running".
Make sure you are running the code or executable as administrator.
You probably opened the file but couldn't save the changes to the file for the friend that the code failed.
from another post from here you can check it like this:
using System.Security.Principal;
public bool IsUserAdministrator()
{
bool isAdmin;
try
{
WindowsIdentity user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch (UnauthorizedAccessException ex)
{
isAdmin = false;
}
catch (Exception ex)
{
isAdmin = false;
}
return isAdmin;
}

Cannot authenticate against Apache DS using C# and LdapConnection?

Problem
I installed and configured a ApacheDS server running ldap. This was a huge step forward for me in teaching myself ldap. However, the following C# console code returns the following error:
System.DirectoryServices.Protocols.LdapException {"The supplied credential is invalid"}
My code is to use this sample code to authenticate a sample user.
Code
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SampleLdapAuthentication
{
class Program
{
static void Main(string[] args)
{
RunLdap run = new RunLdap("localhost", "organization", 635, "hderp", "spaceballs1234");
bool result = run.ValidateCredentials();
if(result)
{
Console.WriteLine("Authentication Succeeded");
}
else
{
Console.WriteLine("Authentication Failed");
}
}
}
}
SampleLdapAuthentication.cs
using System;
using System.Collections.Generic;
using System.DirectoryServices.Protocols;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace SampleLdapAuthentication
{
public class RunLdap
{
private static string _domainController;
private static string _domain;
private static int _port;
private static string _userName;
private static string _userPassword;
//Constructor. Takes the domain controller, domain, port, username, and password and then calls Ldap Method to run authentication
public RunLdap(string domainController, string domain, int port, string userName, string userPassword)
{
_domainController = domainController;
_domain = null;
_port = port;
_userName = userName;
_userPassword = userPassword;
}
public bool ValidateCredentials()
{
LdapDirectoryIdentifier ldi = new LdapDirectoryIdentifier(_domainController, _port);
NetworkCredential networkCredential = new NetworkCredential(_userName, _userPassword, _domain);
try
{
//We use using so we dispose the object as soon as it goes out of scope
using (LdapConnection connection = new LdapConnection(ldi))
{
//connection.SessionOptions.SecureSocketLayer = true;
connection.AuthType = AuthType.Kerberos;
connection.Bind(networkCredential);
//Not sure what this is doing
}
return true;
}
catch(LdapException ldapException)
{
return false;
}
return false;
}//End of ValidateCredentials
}
}
LDAP Server Details
Notes
The following are worth noting in what I am doing:
I followed this tutorial in creating the server and DIT.
According to my understanding ApacheDS supports keberos out of the box now, so my authentication type should be fine. That is, AuthType
It fails on connection.Bind() method
I am thinking maybe there is something wrong with how I am entering in the credentials and that my C# code is fine. That is why I included the server AD information. I am new to LDAP and using it to authenticate users, so I appreciate your help.
You're not using the distinguished name of the user. When you create your NetworkCredential object, you should be using the distingushed name of the user, in this case, cn=Herp Derp,ou=users,o=organization instead of hderp. The LDAP doesn't know where to look for hderp without the o and ou values.

Categories

Resources