简体   繁体   中英

How to use firebase login with email and password on Android

When I tried to follow the Firebase website for tutorial ( https://www.firebase.com/docs/web/guide/login/password.html ) on developing a simple login on android studio, I faced error, with red wiggly lines.

Could someone help me or suggest a good place to learn about step by step tutorial on how to create a simple login using firebase. Resources on firebase login for android are very limited online. Would be great if someone could help me .

This is the code copied from firebase website for login, when I paste it into my code I have red error on email password function error UserData etc etc.

   mRef.createUser({
            email    : "bobtony@firebase.com",
            password : "correcthorsebatterystaple"
    }, function(error, userData) {
        if (error) {
            console.log("Error creating user:", error);
        } else {
            console.log("Successfully created user account with uid:", userData.uid);
        }
    });
ref.createUser("bobtony@firebase.com", "correcthorsebatterystaple", new Firebase.ValueResultHandler<Map<String, Object>>() { @Override public void onSuccess(Map<String, Object> result) { System.out.println("Successfully created user account with uid: " + result.get("uid")); } @Override public void onError(FirebaseError firebaseError) { // there was an error }

很抱歉它在一条线上,我目前正在使用电话并且它不能很好地处理代码我从https://www.firebase.com/docs/android/guide/login/password.html获得了代码

As mentioned above Firebase has a library https://github.com/firebase/FirebaseUI-Android that has useful tools including login. Sounds like you went through the code lab posted by Frank van Puffelen.

If it is helpful, I have been working on a project that uses their library but adds additional functionality like new user registration, saving user data (like the new users name) into your Firebase database, etc and with, hopefully, easy implementation. I have step by step instructions on how to add my code to your project with my base example the code added to a blank Android project.

The project includes Google Auth as well. https://github.com/cardenuto/FirebaseLogin

to login using firebase with username and password

 auth.signInWithEmailAndPassword(
    edt_username.text.toString().trim(),
    edt_password.text.toString().trim()
)
    .addOnCompleteListener(this) { task ->
        if (task.isSuccessful) {
            // Sign in success, update UI with the signed-in user's information
            Log.d("Status", "signInWithEmail:success")
            val user = auth.currentUser

            showAlert("User Logged-in Successfully ","Welcome :"+user)

        } else {
            // If sign in fails, display a message to the user.
            Log.w("Status", "signInWithEmail:failure", task.exception)
            showAlert("User not found ","Register")

        }

    }

http://www.androidcoding.in/2020/06/02/android-firebase-login-tutorial/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM