2016-10-17 76 views
4

有沒有辦法知道用戶輸入的電子郵件在Firebase中是否真實?內置的用電子郵件&註冊的密碼方法有這個功能嗎?檢查給定的電子郵件是否存在

編輯:抱歉的誤解。我不在乎,如果電子郵件已經被使用過,我需要知道的是:如果輸入的電子郵件「編造」或者「真正的,存在」

+0

您可能正在尋找:http://stackoverflow.com/questions/40090406/ambiguous-use-of-subscript-swift-3/40092330#40092330 –

+0

如果您想知道電子​​郵件地址是否實際由用戶擁有,您的應用可以調用user.sendEmailVerification():https://firebase.google.com/docs/auth/android/manage-users#send_a_user_a_verification_email –

回答

6

是的,你要麼你創建新的可以做在帳戶或簽名:

用於創建,讀取createUserWithEmailAndPasswordDocs

createUserWithEmailAndPassword拋出3個例外:

  1. FirebaseAuthWeakPasswordException:如果密碼不夠強
  2. FirebaseAuthInvalidCredentialsException:如果電子郵件地址的格式不正確

  3. FirebaseAuthUserCollisionException如果已經存在給定的電子郵件地址帳戶。

您可以處理在onCompleteListeneronFailureListener

下面一個例子,其中mAuthFirebaseAuth例如:

mAuth.createUserWithEmailAndPassword(email, password) 
      .addOnCompleteListener(
        new OnCompleteListener<AuthResult>() 
        { 
         @Override 
         public void onComplete(@NonNull Task<AuthResult> task) 
         { 
          if (!task.isSuccessful()) 
          { 
           try 
           { 
            throw task.getException(); 
           } 
           // if user enters wrong email. 
           catch (FirebaseAuthWeakPasswordException weakPassword) 
           { 
            Log.d(TAG, "onComplete: weak_password"); 

            // TODO: take your actions! 
           } 
           // if user enters wrong password. 
           catch (FirebaseAuthInvalidCredentialsException malformedEmail) 
           { 
            Log.d(TAG, "onComplete: malformed_email"); 

            // TODO: Take your action 
           } 
           catch (FirebaseAuthUserCollisionException existEmail) 
           { 
            Log.d(TAG, "onComplete: exist_email"); 

            // TODO: Take your action 
           } 
           catch (Exception e) 
           { 
            Log.d(TAG, "onComplete: " + e.getMessage()); 
           } 
          } 
         } 
        } 
      ); 

,用於登錄,閱讀signInWithEmailAndPasswordDocs第一。

signInWithEmailAndPassword拋出兩個例外:

  1. FirebaseAuthInvalidUserException:如果電子郵件地址不存在或禁用。
  2. FirebaseAuthInvalidCredentialsException:如果密碼錯誤

下面是一個例子:

mAuth.signInWithEmailAndPassword(email, password) 
      .addOnCompleteListener(
        new OnCompleteListener<AuthResult>() 
        { 
         @Override 
         public void onComplete(@NonNull Task<AuthResult> task) 
         { 
          if (!task.isSuccessful()) 
          { 
           try 
           { 
            throw task.getException(); 
           } 
           // if user enters wrong email. 
           catch (FirebaseAuthInvalidUserException invalidEmail) 
           { 
            Log.d(TAG, "onComplete: invalid_email"); 

            // TODO: take your actions! 
           } 
           // if user enters wrong password. 
           catch (FirebaseAuthInvalidCredentialsException wrongPassword) 
           { 
            Log.d(TAG, "onComplete: wrong_password"); 

            // TODO: Take your action 
           } 
           catch (Exception e) 
           { 
            Log.d(TAG, "onComplete: " + e.getMessage()); 
           } 
          } 
         } 
        } 
      );