skip to Main Content

I am facing this error when I try to click the login button

Initial task failed for action RecaptchaAction(action=signInWithPassword)with exception – The supplied auth credential is incorrect, malformed or has expired.

I want to make a login activity and so far my code is this

LoginActivity.kt

package com.example.cafe

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.textfield.TextInputEditText
import com.google.firebase.Firebase
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.auth


class LoginActivity : AppCompatActivity() {
    private lateinit var auth: FirebaseAuth

    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
        val email = findViewById<TextInputEditText>(R.id.loginEmail)
        val password = findViewById<TextInputEditText>(R.id.loginpassword)
        val loginBtn = findViewById<Button>(R.id.signinBtn)
        auth = Firebase.auth

        loginBtn.setOnClickListener {
            val mail = email.text.toString()
            val pass = password.text.toString()

            if(mail.isNotEmpty() && pass.isNotEmpty()) {
                auth.signInWithEmailAndPassword(mail, pass).addOnCompleteListener {
                    if(it.isSuccessful){
                       val intent = Intent(this,MainActivity::class.java)
                        startActivity(intent)
                    }else{
                        Toast.makeText(this,it.exception.toString(),Toast.LENGTH_LONG).show()
                    }
                }
            }  else{
                Toast.makeText(this,"Fields cannot be empty",Toast.LENGTH_LONG).show()
            }
        }
    }

}

Menifest file



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Cafe"
        tools:targetApi="31">
        <activity
            android:name=".LoginActivity"
            android:exported="false" />
        <activity
            android:name=".firstpage"
            android:exported="false" />
        <activity
            android:name=".splashscreen"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".orderActivity"
            android:exported="false" />
        <activity
            android:name=".MainActivity"
            android:exported="false" />
    </application>

</manifest>

**gradle file
**

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("com.google.gms.google-services")
}

android {
    namespace = "com.example.cafe"
    compileSdk = 34
    defaultConfig {
        applicationId = "com.example.cafe"
        minSdk = 24
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }


    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {

    implementation("androidx.core:core-ktx:1.12.0")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.11.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    implementation("com.google.firebase:firebase-database:20.3.0")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    implementation ("com.google.firebase:firebase-core:21.1.1")
    implementation ("com.google.firebase:firebase-auth:22.3.1")
    implementation(platform("com.google.firebase:firebase-bom:32.7.2"))
    implementation("com.google.firebase:firebase-auth")


}

2

Answers


  1. Chosen as BEST ANSWER

    I tried to add SHA-1 and SHA-256 fingerprints in the firebase and everything worked fine after that.


  2. this was a problem for me, so I removed it from the project -> implementation(platform("com.google.firebase:firebase-bom:32.7.2"))

    and auth = Firebase.auth is replaced by auth = FirebaseAuth.getInstance()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search