अपने एंड्रॉइड ऐप में मल्टी-फैक्टर प्रमाणीकरण जोड़ें

यदि आपने आइडेंटिटी प्लेटफ़ॉर्म के साथ फ़ायरबेस प्रमाणीकरण में अपग्रेड किया है, तो आप अपने एंड्रॉइड ऐप में एसएमएस मल्टी-फैक्टर प्रमाणीकरण जोड़ सकते हैं।

मल्टी-फैक्टर ऑथेंटिकेशन आपके ऐप की सुरक्षा बढ़ाता है। जबकि हमलावर अक्सर पासवर्ड और सोशल अकाउंट से समझौता कर लेते हैं, टेक्स्ट संदेश को इंटरसेप्ट करना अधिक कठिन होता है।

शुरू करने से पहले

  1. कम से कम एक प्रदाता को सक्षम करें जो बहु-कारक प्रमाणीकरण का समर्थन करता हो। फ़ोन प्रमाणीकरण, अनाम प्रमाणीकरण और ऐप्पल गेम सेंटर को छोड़कर , प्रत्येक प्रदाता एमएफए का समर्थन करता है।

  2. सुनिश्चित करें कि आपका ऐप उपयोगकर्ता ईमेल सत्यापित कर रहा है। एमएफए को ईमेल सत्यापन की आवश्यकता है। यह दुर्भावनापूर्ण अभिनेताओं को किसी ऐसे ईमेल के साथ सेवा के लिए पंजीकरण करने से रोकता है जो उनके पास नहीं है, और फिर एक दूसरा कारक जोड़कर वास्तविक मालिक को लॉक कर देता है।

  3. अपने ऐप के SHA-1 हैश को फायरबेस कंसोल में पंजीकृत करें (आपके परिवर्तन स्वचालित रूप से Google क्लाउड फायरबेस पर ले जाए जाएंगे)।

    1. अपने ऐप का SHA-1 हैश प्राप्त करने के लिए अपने क्लाइंट को प्रमाणित करने के चरणों का पालन करें।

    2. फायरबेस कंसोल खोलें।

    3. प्रोजेक्ट सेटिंग्स पर नेविगेट करें।

    4. आपके ऐप्स के अंतर्गत, Android आइकन पर क्लिक करें।

    5. अपना SHA-1 हैश जोड़ने के लिए निर्देशित चरणों का पालन करें।

बहु-कारक प्रमाणीकरण सक्षम करना

  1. फायरबेस कंसोल का प्रमाणीकरण > साइन-इन विधि पृष्ठ खोलें।

  2. उन्नत अनुभाग में, एसएमएस मल्टी-फैक्टर प्रमाणीकरण सक्षम करें।

    आपको वे फ़ोन नंबर भी दर्ज करने चाहिए जिनसे आप अपने ऐप का परीक्षण करेंगे। वैकल्पिक होते हुए भी, विकास के दौरान थ्रॉटलिंग से बचने के लिए परीक्षण फ़ोन नंबर पंजीकृत करने की पुरजोर अनुशंसा की जाती है।

  3. यदि आपने पहले से ही अपने ऐप के डोमेन को अधिकृत नहीं किया है, तो इसे फायरबेस कंसोल के प्रमाणीकरण> सेटिंग्स पृष्ठ पर अनुमति सूची में जोड़ें।

नामांकन पैटर्न चुनना

आप चुन सकते हैं कि आपके ऐप को बहु-कारक प्रमाणीकरण की आवश्यकता है या नहीं, और अपने उपयोगकर्ताओं को कैसे और कब नामांकित करना है। कुछ सामान्य पैटर्न में शामिल हैं:

  • पंजीकरण के भाग के रूप में उपयोगकर्ता के दूसरे कारक को नामांकित करें। यदि आपके ऐप को सभी उपयोगकर्ताओं के लिए बहु-कारक प्रमाणीकरण की आवश्यकता है तो इस विधि का उपयोग करें।

  • पंजीकरण के दौरान दूसरे कारक को नामांकित करने के लिए एक स्किप करने योग्य विकल्प प्रदान करें। ऐसे ऐप्स जो बहु-कारक प्रमाणीकरण को प्रोत्साहित करना चाहते हैं, लेकिन इसकी आवश्यकता नहीं है, वे इस दृष्टिकोण को पसंद कर सकते हैं।

  • साइन अप स्क्रीन के बजाय उपयोगकर्ता के खाते या प्रोफ़ाइल प्रबंधन पृष्ठ से दूसरा कारक जोड़ने की क्षमता प्रदान करें। यह पंजीकरण प्रक्रिया के दौरान घर्षण को कम करता है, साथ ही सुरक्षा-संवेदनशील उपयोगकर्ताओं के लिए बहु-कारक प्रमाणीकरण भी उपलब्ध कराता है।

  • जब उपयोगकर्ता बढ़ी हुई सुरक्षा आवश्यकताओं के साथ सुविधाओं का उपयोग करना चाहता है तो उसे क्रमिक रूप से एक दूसरा कारक जोड़ने की आवश्यकता होती है।

दूसरे कारक का नामांकन

किसी उपयोगकर्ता के लिए एक नया द्वितीयक कारक नामांकित करने के लिए:

  1. उपयोगकर्ता को पुनः प्रमाणित करें.

  2. उपयोगकर्ता से उनका फ़ोन नंबर दर्ज करने के लिए कहें।

  3. उपयोगकर्ता के लिए बहु-कारक सत्र प्राप्त करें:

    Kotlin+KTX

    user.multiFactor.session.addOnCompleteListener { task ->
        if (task.isSuccessful) {
            val multiFactorSession: MultiFactorSession? = task.result
        }
    }
    

    Java

    user.getMultiFactor().getSession()
      .addOnCompleteListener(
          new OnCompleteListener<MultiFactorSession>() {
          @Override
          public void onComplete(@NonNull Task<MultiFactorSession> task) {
            if (task.isSuccessful()) {
              MultiFactorSession multiFactorSession = task.getResult();
            }
          }
          });
    
  4. सत्यापन प्रक्रिया में विभिन्न घटनाओं को संभालने के लिए एक OnVerificationStateChangedCallbacks ऑब्जेक्ट बनाएं:

    Kotlin+KTX

    val callbacks = object : OnVerificationStateChangedCallbacks() {
        override fun onVerificationCompleted(credential: PhoneAuthCredential) {
            // This callback will be invoked in two situations:
            // 1) Instant verification. In some cases, the phone number can be
            //    instantly verified without needing to send or enter a verification
            //    code. You can disable this feature by calling
            //    PhoneAuthOptions.builder#requireSmsValidation(true) when building
            //    the options to pass to PhoneAuthProvider#verifyPhoneNumber().
            // 2) Auto-retrieval. On some devices, Google Play services can
            //    automatically detect the incoming verification SMS and perform
            //    verification without user action.
            this@MainActivity.credential = credential
        }
    
        override fun onVerificationFailed(e: FirebaseException) {
            // This callback is invoked in response to invalid requests for
            // verification, like an incorrect phone number.
            if (e is FirebaseAuthInvalidCredentialsException) {
                // Invalid request
                // ...
            } else if (e is FirebaseTooManyRequestsException) {
                // The SMS quota for the project has been exceeded
                // ...
            }
            // Show a message and update the UI
            // ...
        }
    
        override fun onCodeSent(
            verificationId: String, forceResendingToken: ForceResendingToken
        ) {
            // The SMS verification code has been sent to the provided phone number.
            // We now need to ask the user to enter the code and then construct a
            // credential by combining the code with a verification ID.
            // Save the verification ID and resending token for later use.
            this@MainActivity.verificationId = verificationId
            this@MainActivity.forceResendingToken = forceResendingToken
            // ...
        }
    }
    

    Java

    OnVerificationStateChangedCallbacks callbacks =
    new OnVerificationStateChangedCallbacks() {
      @Override
      public void onVerificationCompleted(PhoneAuthCredential credential) {
        // This callback will be invoked in two situations:
        // 1) Instant verification. In some cases, the phone number can be
        //    instantly verified without needing to send or enter a verification
        //    code. You can disable this feature by calling
        //    PhoneAuthOptions.builder#requireSmsValidation(true) when building
        //    the options to pass to PhoneAuthProvider#verifyPhoneNumber().
        // 2) Auto-retrieval. On some devices, Google Play services can
        //    automatically detect the incoming verification SMS and perform
        //    verification without user action.
        this.credential = credential;
      }
      @Override
      public void onVerificationFailed(FirebaseException e) {
        // This callback is invoked in response to invalid requests for
        // verification, like an incorrect phone number.
        if (e instanceof FirebaseAuthInvalidCredentialsException) {
        // Invalid request
        // ...
        } else if (e instanceof FirebaseTooManyRequestsException) {
        // The SMS quota for the project has been exceeded
        // ...
        }
        // Show a message and update the UI
        // ...
      }
      @Override
      public void onCodeSent(
        String verificationId, PhoneAuthProvider.ForceResendingToken token) {
        // The SMS verification code has been sent to the provided phone number.
        // We now need to ask the user to enter the code and then construct a
        // credential by combining the code with a verification ID.
        // Save the verification ID and resending token for later use.
        this.verificationId = verificationId;
        this.forceResendingToken = token;
        // ...
      }
    };
    
  5. उपयोगकर्ता के फ़ोन नंबर, बहु-कारक सत्र और अपने कॉलबैक के साथ PhoneInfoOptions ऑब्जेक्ट को प्रारंभ करें:

    Kotlin+KTX

    val phoneAuthOptions = PhoneAuthOptions.newBuilder()
        .setPhoneNumber(phoneNumber)
        .setTimeout(30L, TimeUnit.SECONDS)
        .setMultiFactorSession(MultiFactorSession)
        .setCallbacks(callbacks)
        .build()
    

    Java

    PhoneAuthOptions phoneAuthOptions =
      PhoneAuthOptions.newBuilder()
          .setPhoneNumber(phoneNumber)
          .setTimeout(30L, TimeUnit.SECONDS)
          .setMultiFactorSession(multiFactorSession)
          .setCallbacks(callbacks)
          .build();
    

    डिफ़ॉल्ट रूप से, तत्काल सत्यापन सक्षम है। इसे अक्षम करने के लिए, requireSmsValidation(true) पर एक कॉल जोड़ें।

  6. उपयोगकर्ता के फ़ोन पर एक सत्यापन संदेश भेजें:

    Kotlin+KTX

    PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions)
    

    Java

    PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions);
    

    हालाँकि यह आवश्यक नहीं है, उपयोगकर्ताओं को पहले से सूचित करना सर्वोत्तम अभ्यास है कि उन्हें एक एसएमएस संदेश प्राप्त होगा, और मानक दरें लागू होंगी।

  7. एक बार एसएमएस कोड भेजे जाने के बाद, उपयोगकर्ता से कोड सत्यापित करने के लिए कहें:

    Kotlin+KTX

    // Ask user for the verification code.
    val credential = PhoneAuthProvider.getCredential(verificationId, verificationCode)
    

    Java

    // Ask user for the verification code.
    PhoneAuthCredential credential
      = PhoneAuthProvider.getCredential(verificationId, verificationCode);
    
  8. PhoneAuthCredential के साथ एक MultiFactorAssertion ऑब्जेक्ट प्रारंभ करें:

    Kotlin+KTX

    val multiFactorAssertion
      = PhoneMultiFactorGenerator.getAssertion(credential)
    

    Java

    MultiFactorAssertion multiFactorAssertion
      = PhoneMultiFactorGenerator.getAssertion(credential);
    
  9. नामांकन पूरा करें. वैकल्पिक रूप से, आप दूसरे कारक के लिए एक प्रदर्शन नाम निर्दिष्ट कर सकते हैं। यह एकाधिक सेकंड कारकों वाले उपयोगकर्ताओं के लिए उपयोगी है, क्योंकि प्रमाणीकरण प्रवाह के दौरान फ़ोन नंबर छिपा हुआ होता है (उदाहरण के लिए, +1******1234)।

    Kotlin+KTX

    // Complete enrollment. This will update the underlying tokens
    // and trigger ID token change listener.
    FirebaseAuth.getInstance()
        .currentUser
        ?.multiFactor
        ?.enroll(multiFactorAssertion, "My personal phone number")
        ?.addOnCompleteListener {
            // ...
        }
    

    Java

    // Complete enrollment. This will update the underlying tokens
    // and trigger ID token change listener.
    FirebaseAuth.getInstance()
      .getCurrentUser()
      .getMultiFactor()
      .enroll(multiFactorAssertion, "My personal phone number")
      .addOnCompleteListener(
          new OnCompleteListener<Void>() {
          @Override
          public void onComplete(@NonNull Task<Void> task) {
            // ...
          }
          });
    

नीचे दिया गया कोड दूसरे कारक को नामांकित करने का एक पूरा उदाहरण दिखाता है:

Kotlin+KTX

val multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential)
user.multiFactor.session
    .addOnCompleteListener { task ->
        if (task.isSuccessful) {
            val multiFactorSession = task.result
            val phoneAuthOptions = PhoneAuthOptions.newBuilder()
                .setPhoneNumber(phoneNumber)
                .setTimeout(30L, TimeUnit.SECONDS)
                .setMultiFactorSession(multiFactorSession)
                .setCallbacks(callbacks)
                .build()
            // Send SMS verification code.
            PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions)
        }
    }

// Ask user for the verification code.
val credential = PhoneAuthProvider.getCredential(verificationId, verificationCode)

val multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential)

// Complete enrollment.
FirebaseAuth.getInstance()
    .currentUser
    ?.multiFactor
    ?.enroll(multiFactorAssertion, "My personal phone number")
    ?.addOnCompleteListener {
        // ...
    }

Java

MultiFactorAssertion multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential);
user.getMultiFactor().getSession()
  .addOnCompleteListener(
      new OnCompleteListener<MultiFactorSession>() {
      @Override
      public void onComplete(@NonNull Task<MultiFactorSession> task) {
        if (task.isSuccessful()) {
          MultiFactorSession multiFactorSession = task.getResult();
          PhoneAuthOptions phoneAuthOptions =
            PhoneAuthOptions.newBuilder()
                .setPhoneNumber(phoneNumber)
                .setTimeout(30L, TimeUnit.SECONDS)
                .setMultiFactorSession(multiFactorSession)
                .setCallbacks(callbacks)
                .build();
          // Send SMS verification code.
          PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions);
        }
      }
      });

// Ask user for the verification code.
PhoneAuthCredential credential =
  PhoneAuthProvider.getCredential(verificationId, verificationCode);

MultiFactorAssertion multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential);
// Complete enrollment.
FirebaseAuth.getInstance()
  .getCurrentUser()
  .getMultiFactor()
  .enroll(multiFactorAssertion, "My personal phone number")
  .addOnCompleteListener(
      new OnCompleteListener<Void>() {
      @Override
      public void onComplete(@NonNull Task<Void> task) {
        // ...
      }
      });

बधाई हो! आपने एक उपयोगकर्ता के लिए दूसरा प्रमाणीकरण कारक सफलतापूर्वक पंजीकृत किया है।

उपयोगकर्ताओं को दूसरे कारक से साइन इन करना

किसी उपयोगकर्ता को दो-कारक एसएमएस सत्यापन के साथ साइन इन करने के लिए:

  1. उपयोगकर्ता को उनके पहले कारक के साथ साइन इन करें, फिर FirebaseAuthMultiFactorException अपवाद को पकड़ें। इस त्रुटि में एक रिज़ॉल्वर शामिल है, जिसका उपयोग आप उपयोगकर्ता के नामांकित दूसरे कारकों को प्राप्त करने के लिए कर सकते हैं। इसमें एक अंतर्निहित सत्र भी शामिल है जो साबित करता है कि उपयोगकर्ता अपने पहले कारक के साथ सफलतापूर्वक प्रमाणित है।

    उदाहरण के लिए, यदि उपयोगकर्ता का पहला कारक ईमेल और पासवर्ड था:

    Kotlin+KTX

    FirebaseAuth.getInstance()
        .signInWithEmailAndPassword(email, password)
        .addOnCompleteListener(
            OnCompleteListener { task ->
                if (task.isSuccessful) {
                    // User is not enrolled with a second factor and is successfully
                    // signed in.
                    // ...
                    return@OnCompleteListener
                }
                if (task.exception is FirebaseAuthMultiFactorException) {
                    // The user is a multi-factor user. Second factor challenge is
                    // required.
                    val multiFactorResolver =
                        (task.exception as FirebaseAuthMultiFactorException).resolver
                    // ...
                } else {
                    // Handle other errors, such as wrong password.
                }
            })
    

    Java

    FirebaseAuth.getInstance()
      .signInWithEmailAndPassword(email, password)
      .addOnCompleteListener(
          new OnCompleteListener<AuthResult>() {
          @Override
          public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
              // User is not enrolled with a second factor and is successfully
              // signed in.
              // ...
              return;
            }
            if (task.getException() instanceof FirebaseAuthMultiFactorException) {
              // The user is a multi-factor user. Second factor challenge is
              // required.
              MultiFactorResolver multiFactorResolver = task.getException().getResolver();
              // ...
            } else {
              // Handle other errors such as wrong password.
            }
          }
          });
    

    यदि उपयोगकर्ता का पहला कारक एक फ़ेडरेटेड प्रदाता है, जैसे कि OAuth, तो startActivityForSignInWithProvider() कॉल करने के बाद त्रुटि पकड़ें।

  2. यदि उपयोगकर्ता के पास एकाधिक द्वितीयक कारक नामांकित हैं, तो उनसे पूछें कि किसका उपयोग करना है:

    Kotlin+KTX

    // Ask user which second factor to use.
    // You can get the list of enrolled second factors using
    //   multiFactorResolver.hints
    
    // Check the selected factor:
    if (multiFactorResolver.hints[selectedIndex].factorId
        === PhoneMultiFactorGenerator.FACTOR_ID
    ) {
        // User selected a phone second factor.
        val selectedHint =
            multiFactorResolver.hints[selectedIndex] as PhoneMultiFactorInfo
    } else if (multiFactorResolver.hints[selectedIndex].factorId
        === TotpMultiFactorGenerator.FACTOR_ID) {
        // User selected a TOTP second factor.
    } else {
        // Unsupported second factor.
    }
    

    Java

    // Ask user which second factor to use.
    // You can get the masked phone number using
    // resolver.getHints().get(selectedIndex).getPhoneNumber()
    // You can get the display name using
    // resolver.getHints().get(selectedIndex).getDisplayName()
    if ( resolver.getHints()
                   .get(selectedIndex)
                   .getFactorId()
                   .equals( PhoneMultiFactorGenerator.FACTOR_ID ) ) {
    // User selected a phone second factor.
    MultiFactorInfo selectedHint =
      multiFactorResolver.getHints().get(selectedIndex);
    } else if ( resolver
                  .getHints()
                  .get(selectedIndex)
                  .getFactorId()
                  .equals(TotpMultiFactorGenerator.FACTOR_ID ) ) {
      // User selected a TOTP second factor.
    } else {
    // Unsupported second factor.
    }
    
  3. संकेत और बहु-कारक सत्र के साथ PhoneAuthOptions ऑब्जेक्ट को प्रारंभ करें। ये मान FirebaseAuthMultiFactorException से जुड़े रिज़ॉल्वर में समाहित हैं।

    Kotlin+KTX

    val phoneAuthOptions = PhoneAuthOptions.newBuilder()
        .setMultiFactorHint(selectedHint)
        .setTimeout(30L, TimeUnit.SECONDS)
        .setMultiFactorSession(multiFactorResolver.session)
        .setCallbacks(callbacks) // Optionally disable instant verification.
        // .requireSmsValidation(true)
        .build()
    

    Java

    PhoneAuthOptions phoneAuthOptions =
      PhoneAuthOptions.newBuilder()
          .setMultiFactorHint(selectedHint)
          .setTimeout(30L, TimeUnit.SECONDS)
          .setMultiFactorSession(multiFactorResolver.getSession())
          .setCallbacks(callbacks)
          // Optionally disable instant verification.
          // .requireSmsValidation(true)
          .build();
    
  4. उपयोगकर्ता के फ़ोन पर एक सत्यापन संदेश भेजें:

    Kotlin+KTX

    // Send SMS verification code
    PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions)
    

    Java

    // Send SMS verification code
    PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions);
    
  5. एक बार एसएमएस कोड भेजे जाने के बाद, उपयोगकर्ता से कोड सत्यापित करने के लिए कहें:

    Kotlin+KTX

    // Ask user for the verification code. Then, pass it to getCredential:
    val credential =
        PhoneAuthProvider.getCredential(verificationId, verificationCode)
    

    Java

    // Ask user for the verification code. Then, pass it to getCredential:
    PhoneAuthCredential credential
        = PhoneAuthProvider.getCredential(verificationId, verificationCode);
    
  6. PhoneAuthCredential के साथ एक MultiFactorAssertion ऑब्जेक्ट प्रारंभ करें:

    Kotlin+KTX

    val multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential)
    

    Java

    MultiFactorAssertion multiFactorAssertion
        = PhoneMultiFactorGenerator.getAssertion(credential);
    
  7. द्वितीयक प्रमाणीकरण पूरा करने के लिए resolver.resolveSignIn() को कॉल करें। फिर आप मूल साइन-इन परिणाम तक पहुंच सकते हैं, जिसमें मानक प्रदाता-विशिष्ट डेटा और प्रमाणीकरण क्रेडेंशियल शामिल हैं:

    Kotlin+KTX

    multiFactorResolver
        .resolveSignIn(multiFactorAssertion)
        .addOnCompleteListener { task ->
            if (task.isSuccessful) {
                val authResult = task.result
                // AuthResult will also contain the user, additionalUserInfo,
                // and an optional credential (null for email/password)
                // associated with the first factor sign-in.
    
                // For example, if the user signed in with Google as a first
                // factor, authResult.getAdditionalUserInfo() will contain data
                // related to Google provider that the user signed in with;
                // authResult.getCredential() will contain the Google OAuth
                //   credential;
                // authResult.getCredential().getAccessToken() will contain the
                //   Google OAuth access token;
                // authResult.getCredential().getIdToken() contains the Google
                //   OAuth ID token.
            }
        }
    

    Java

    multiFactorResolver
      .resolveSignIn(multiFactorAssertion)
      .addOnCompleteListener(
          new OnCompleteListener<AuthResult>() {
          @Override
          public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
              AuthResult authResult = task.getResult();
              // AuthResult will also contain the user, additionalUserInfo,
              // and an optional credential (null for email/password)
              // associated with the first factor sign-in.
              // For example, if the user signed in with Google as a first
              // factor, authResult.getAdditionalUserInfo() will contain data
              // related to Google provider that the user signed in with.
              // authResult.getCredential() will contain the Google OAuth
              // credential.
              // authResult.getCredential().getAccessToken() will contain the
              // Google OAuth access token.
              // authResult.getCredential().getIdToken() contains the Google
              // OAuth ID token.
            }
          }
          });
    

नीचे दिया गया कोड मल्टी-फैक्टर उपयोगकर्ता में साइन इन करने का एक पूरा उदाहरण दिखाता है:

Kotlin+KTX

FirebaseAuth.getInstance()
    .signInWithEmailAndPassword(email, password)
    .addOnCompleteListener { task ->
        if (task.isSuccessful) {
            // User is not enrolled with a second factor and is successfully
            // signed in.
            // ...
            return@addOnCompleteListener
        }
        if (task.exception is FirebaseAuthMultiFactorException) {
            val multiFactorResolver =
                (task.exception as FirebaseAuthMultiFactorException).resolver

            // Ask user which second factor to use. Then, get
            // the selected hint:
            val selectedHint =
                multiFactorResolver.hints[selectedIndex] as PhoneMultiFactorInfo

            // Send the SMS verification code.
            PhoneAuthProvider.verifyPhoneNumber(
                PhoneAuthOptions.newBuilder()
                    .setActivity(this)
                    .setMultiFactorSession(multiFactorResolver.session)
                    .setMultiFactorHint(selectedHint)
                    .setCallbacks(generateCallbacks())
                    .setTimeout(30L, TimeUnit.SECONDS)
                    .build()
            )

            // Ask user for the SMS verification code, then use it to get
            // a PhoneAuthCredential:
            val credential =
                PhoneAuthProvider.getCredential(verificationId, verificationCode)

            // Initialize a MultiFactorAssertion object with the
            // PhoneAuthCredential.
            val multiFactorAssertion: MultiFactorAssertion =
                PhoneMultiFactorGenerator.getAssertion(credential)

            // Complete sign-in.
            multiFactorResolver
                .resolveSignIn(multiFactorAssertion)
                .addOnCompleteListener { task ->
                    if (task.isSuccessful) {
                        // User successfully signed in with the
                        // second factor phone number.
                    }
                    // ...
                }
        } else {
            // Handle other errors such as wrong password.
        }
    }

Java

FirebaseAuth.getInstance()
  .signInWithEmailAndPassword(email, password)
  .addOnCompleteListener(
      new OnCompleteListener<AuthResult>() {
      @Override
      public void onComplete(@NonNull Task<AuthResult> task) {
        if (task.isSuccessful()) {
          // User is not enrolled with a second factor and is successfully
          // signed in.
          // ...
          return;
        }
        if (task.getException() instanceof FirebaseAuthMultiFactorException) {
          FirebaseAuthMultiFactorException e =
            (FirebaseAuthMultiFactorException) task.getException();

          MultiFactorResolver multiFactorResolver = e.getResolver();

          // Ask user which second factor to use.
          MultiFactorInfo selectedHint =
            multiFactorResolver.getHints().get(selectedIndex);

          // Send the SMS verification code.
          PhoneAuthProvider.verifyPhoneNumber(
            PhoneAuthOptions.newBuilder()
                .setActivity(this)
                .setMultiFactorSession(multiFactorResolver.getSession())
                .setMultiFactorHint(selectedHint)
                .setCallbacks(generateCallbacks())
                .setTimeout(30L, TimeUnit.SECONDS)
                .build());

          // Ask user for the SMS verification code.
          PhoneAuthCredential credential =
            PhoneAuthProvider.getCredential(verificationId, verificationCode);

          // Initialize a MultiFactorAssertion object with the
          // PhoneAuthCredential.
          MultiFactorAssertion multiFactorAssertion =
            PhoneMultiFactorGenerator.getAssertion(credential);

          // Complete sign-in.
          multiFactorResolver
            .resolveSignIn(multiFactorAssertion)
            .addOnCompleteListener(
                new OnCompleteListener<AuthResult>() {
                  @Override
                  public void onComplete(@NonNull Task<AuthResult> task) {
                  if (task.isSuccessful()) {
                    // User successfully signed in with the
                    // second factor phone number.
                  }
                  // ...
                  }
                });
        } else {
          // Handle other errors such as wrong password.
        }
      }
      });

बधाई हो! आपने बहु-कारक प्रमाणीकरण का उपयोग करके किसी उपयोगकर्ता में सफलतापूर्वक साइन इन किया है।

आगे क्या होगा