gpt4 book ai didi

java - 无需使用 Firebase Phone Auth 登录即可进行移动 OTP 验证

转载 作者:太空宇宙 更新时间:2023-11-03 10:57:17 25 4
gpt4 key购买 nike

我目前正在制作一个 Android 应用程序,我需要在其中验证用户是否使用 OTP 输入了正确的手机号码。用户已经使用他的电子邮件和密码在应用程序中登录。现在我需要验证用户输入的手机号码,而无需使用 firebase phone auth 的 signInWithCrendntial() 方法。我该怎么做?

我的 mCallbacks 是

                @Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
Toast.makeText(getApplicationContext(), "Verification Complete", Toast.LENGTH_SHORT).show();

showMessage("Success!!","OTP verified!" + credential);
cred = credential;
//btn_add_guest.setEnabled(true);

}

@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(getApplicationContext(), "Verification Failed", Toast.LENGTH_SHORT).show();
Log.i(TAG,"Error is "+e.getMessage());
}

@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(getApplicationContext(), "Code Sent", Toast.LENGTH_SHORT).show();
mVerificationId = verificationId;
mResendToken = token;

Log.i(TAG,"VERFICATION ID IS"+mVerificationId);
Log.i(TAG,"RESEND TOKEN"+mResendToken);
btn_add_guest.setEnabled(false);
}
};

我在 button Pressed 上调用此方法,其中 put_otp 是用户输入 OTP 的 textView。

verifyPhoneNumberWithCode(mVerificationId,put_otp.getText().toString());
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, put_otp.getText().toString());
Log.i(TAG,credential.getProvider());

private void verifyPhoneNumberWithCode(String verificationId, String code) {

Log.i(TAG,"RESEND TOKEN IN METHOD IS"+mResendToken); if(code.equals(mResendToken)&&verificationId.equals(mVerificationId)){
Toast.makeText(AddGuestActivity.this, "Verification Success", Toast.LENGTH_SHORT).show();

btn_add_guest.setEnabled(true);
}
else
Toast.makeText(this,"Please provide correct OTP",Toast.LENGTH_SHORT).show();
}

最佳答案

您可以将电子邮件/密码帐户与电话帐户关联https://firebase.google.com/docs/auth/android/account-linking?authuser=0

关于java - 无需使用 Firebase Phone Auth 登录即可进行移动 OTP 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55371291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com