Authenticate with Firebase using Password-Based Accounts using Unity

You can useFirebase Authentication to let your users authenticate withFirebase using their email addresses and passwords, and to manage your app'spassword-based accounts.

Before you begin

Before you can useFirebase Authentication,you need to:

  • Register your Unity project and configure it to use Firebase.

    • If your Unity project already uses Firebase, then it's alreadyregistered and configured for Firebase.

    • If you don't have a Unity project, you can download asample app.

  • Add theFirebaseUnity SDK (specifically,FirebaseAuth.unitypackage) toyour Unity project.

Find detailed instructions for these initial setup tasks inAdd Firebase to your Unity project.

Note that adding Firebase to your Unity project involves tasks both in theFirebase console and in your open Unity project(for example, you download Firebase config files from the console, then movethem into your Unity project).

Access theFirebase.Auth.FirebaseAuth class

TheFirebaseAuth class is the gateway for all API calls.It is accessible throughFirebaseAuth.DefaultInstance.
Firebase.Auth.FirebaseAuthauth=Firebase.Auth.FirebaseAuth.DefaultInstance;

Create a password-based account

To create a new user account with a password, complete the following steps inyour app's sign-in code:

  1. When a new user signs up using your app's sign-up form, complete any newaccount validation steps that your app requires, such as verifying that thenew account's password was correctly typed and meets your complexityrequirements.
  2. Create a new account by passing the new user's email address and passwordtoFirebaseAuth.CreateUserWithEmailAndPassword:
    auth.CreateUserWithEmailAndPasswordAsync(email,password).ContinueWith(task=>{if(task.IsCanceled){Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: "+task.Exception);return;}// Firebase user has been created.Firebase.Auth.AuthResultresult=task.Result;Debug.LogFormat("Firebase user created successfully: {0} ({1})",result.User.DisplayName,result.User.UserId);});
To protect your project from abuse, Firebase limits the number of newemail/password and anonymous sign-ups that your application can have from thesame IP address in a short period of time. You can request and scheduletemporary changes to this quota from theFirebase console.

Sign in a user with an email address and password

The steps for signing in a user with a password are similar to the steps forcreating a new account. In your app's sign-in function, do the following:

  1. When a user signs in to your app, pass the user's email address andpassword toFirebaseAuth.SignInWithEmailAndPassword:
    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.AuthResultresult=task.Result;Debug.LogFormat("User signed in successfully: {0} ({1})",result.User.DisplayName,result.User.UserId);});
  2. You can also create the credential and sign in like the other workflows:
    Firebase.Auth.Credentialcredential=Firebase.Auth.EmailAuthProvider.GetCredential(email,password);auth.SignInAndRetrieveDataWithCredentialAsync(credential).ContinueWith(task=>{if(task.IsCanceled){Debug.LogError("SignInAndRetrieveDataWithCredentialAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("SignInAndRetrieveDataWithCredentialAsync encountered an error: "+task.Exception);return;}Firebase.Auth.AuthResultresult=task.Result;Debug.LogFormat("User signed in successfully: {0} ({1})",result.User.DisplayName,result.User.UserId);});

Recommended: Set a password policy

You can improve account security by enforcing password complexity requirements.

To configure a password policy for your project, open thePassword policytab on the Authentication Settings page of theFirebase console:

Authentication Settings

Firebase Authentication password policies support the following password requirements:

  • Lowercase character required

  • Uppercase character required

  • Numeric character required

  • Non-alphanumeric character required

    The following characters satisfy the non-alphanumeric character requirement:^ $ * . [ ] { } ( ) ? " ! @ # % & / \ , > < ' : ; | _ ~

  • Minimum password length (ranges from 6 to 30 characters; defaults to 6)

  • Maximum password length (maximum length of 4096 characters)

You can enable password policy enforcement in two modes:

  • Require: Attempts to sign up fail until the user updates to a passwordthat complies with your policy.

  • Notify: Users are allowed to sign up with a non-compliant password. Whenusing this mode, you should check if the user's password complies with thepolicy on the client side and prompt the user in some way to update theirpassword if it does not comply.

New users are always required to choose a password that complies with yourpolicy.

If you have active users, we recommend not enabling force upgrade on sign inunless you intend to block access to users whose passwords don't comply withyour policy. Instead, use notify mode, which allows users to sign in with theircurrent passwords, and inform them of the requirements their password lacks.

Recommended: Enable email enumeration protection

SomeFirebase Authentication methods that take email addresses as parameters throwspecific errors if the email address is unregistered when it must be registered(for example, when signing in with an email address and password), or registeredwhen it must be unused (for example, when changing a user's email address).While this can be helpful for suggesting specific remedies to users, it can alsobe abused by malicious actors to discover the email addresses registered by yourusers.

To mitigate this risk, we recommend youenable email enumeration protectionfor your project using the Google Cloudgcloud tool. Note that enabling thisfeature changesFirebase Authentication's error reporting behavior: be sure your appdoesn't rely on the more specific errors.

Next Steps

After a user signs in for the first time, a new user account is created andlinked to the credentials—that is, the user name and password, phonenumber, or auth provider information—the user signed in with. This newaccount is stored as part of your Firebase project, and can be used to identifya user across every app in your project, regardless of how the user signs in.

  • In your apps, you can get the user's basic profile information from theFirebase.Auth.FirebaseUser object:

    Firebase.Auth.FirebaseUseruser=auth.CurrentUser;if(user!=null){stringname=user.DisplayName;stringemail=user.Email;System.Uriphoto_url=user.PhotoUrl;// The user's Id, unique to the Firebase project.// Do NOT use this value to authenticate with your backend server, if you// have one; use User.TokenAsync() instead.stringuid=user.UserId;}
  • In yourFirebase Realtime Database andCloud StorageSecurity Rules, you can get the signed-in user's unique user ID from theauth variable, and use it to control what data a user can access.

You can allow users to sign in to your app using multiple authenticationproviders bylinking auth provider credentials to anexisting user account.

To sign out a user, callSignOut():

auth.SignOut();

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.