gpt4 book ai didi

java - Firebase 身份验证失败

转载 作者:行者123 更新时间:2023-12-02 11:26:36 24 4
gpt4 key购买 nike

我正在使用 Firebase 通过电子邮件和密码凭据注册用户。

我的 Activity 使用以下代码:

public class SignUpPage extends AppCompatActivity {

private TextView profile;
private EditText screen, mail, pass;
private Button knop;
private Typeface tfc_button;
FirebaseAuth firebaseAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_sign_up_page);
setFontType();

screen = (EditText)findViewById(R.id.SchermNaam);
mail = (EditText)findViewById(R.id.PasWoord);
knop = (Button)findViewById(R.id.SignUp_Button_SignUp);

firebaseAuth = FirebaseAuth.getInstance();
}

public void setFontType(){

profile = (TextView) findViewById(R.id.GebruikersProfiel);
screen = (EditText) findViewById(R.id.SchermNaam);
mail = (EditText) findViewById(R.id.EmailAdres);
pass = (EditText) findViewById(R.id.PasWoord);
knop = (Button) findViewById(R.id.SignUp_Button_SignUp);

tfc_button = Typeface.createFromAsset(getAssets(), "fonts/TEMPSITC.TTF");
profile.setTypeface(tfc_button);
screen.setTypeface(tfc_button);
mail.setTypeface(tfc_button);
pass.setTypeface(tfc_button);
knop.setTypeface(tfc_button);
}

public boolean paswoord_ok (final String passw_check){

Pattern pattern;
Matcher matcher;

final String PASSWORD_PATTERN = "((?=.*\\d).{6,12})";

pattern = Pattern.compile(PASSWORD_PATTERN);
matcher = pattern.matcher(passw_check);

return matcher.matches();
}

public boolean schermnaam_ok(final String scr_name_check){

Pattern pattern;
Matcher matcher;

final String PASSWORD_PATTERN = "(.{5,15})";

pattern = Pattern.compile(PASSWORD_PATTERN);
matcher = pattern.matcher(scr_name_check);

return matcher.matches();
}

//Hoe ga je dit testen?
public void onClickSignUpPage(View view){

String schermnaam = screen.getText().toString().trim();
String emailadres = mail.getText().toString().trim();
String paswoord = pass.getText().toString().trim();

if(TextUtils.isEmpty(schermnaam)){
Toast.makeText(this,"Schermnaam invullen", Toast.LENGTH_SHORT).show();
return;
}

if(TextUtils.isEmpty(emailadres)){
Toast.makeText(this,"Email invullen",Toast.LENGTH_SHORT).show();
return;
}

if(!schermnaam_ok(schermnaam)){
Toast.makeText(this,"schermnaam minstens 5 en maximum 15 tekens", Toast.LENGTH_SHORT).show();
return;
}

if(!paswoord_ok(paswoord)){
Toast.makeText(this,"paswoord tussen 6-12 karakters en minstens 1 cijfer", Toast.LENGTH_SHORT).show();
return;
}

firebaseAuth.createUserWithEmailAndPassword(emailadres.trim(),paswoord)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(SignUpPage.this, "Nieuwe Speler Geregistreerd", Toast.LENGTH_SHORT).show();
}
else {
FirebaseAuthException e = (FirebaseAuthException) task.getException();
Toast.makeText(SignUpPage.this,"Fout in de SignUp"+e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("LoginActivity", "Failed Registration", e);
return;
}
}
});

Intent intent = new Intent(this, SignInPage.class);
startActivity(intent);
}

}

检查任务是否成功的 onCompletListener 表明任务不成功。我收到的错误消息是:

Failed Registration com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The email address is badly formatted.

我尝试将trim() 添加到emailadres.trim(),但这不起作用。

有什么建议吗?

最佳答案

我在分配给“email”变量时使用了错误的 View 。这里是正确的代码..

public class SignUpPage extends AppCompatActivity {

private TextView profile;
private EditText screen, mail, pass;
private Button knop;
private Typeface tfc_button;
FirebaseAuth firebaseAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_sign_up_page);
setFontType();

screen = (EditText)findViewById(R.id.SchermNaam);
mail = (EditText)findViewById(R.id.EmailAdres);
knop = (Button)findViewById(R.id.SignUp_Button_SignUp);

firebaseAuth = FirebaseAuth.getInstance();
}

public void setFontType(){

profile = (TextView) findViewById(R.id.GebruikersProfiel);
screen = (EditText) findViewById(R.id.SchermNaam);
mail = (EditText) findViewById(R.id.EmailAdres);
pass = (EditText) findViewById(R.id.PasWoord);
knop = (Button) findViewById(R.id.SignUp_Button_SignUp);

tfc_button = Typeface.createFromAsset(getAssets(), "fonts/TEMPSITC.TTF");
profile.setTypeface(tfc_button);
screen.setTypeface(tfc_button);
mail.setTypeface(tfc_button);
pass.setTypeface(tfc_button);
knop.setTypeface(tfc_button);
}

public boolean paswoord_ok (final String passw_check){

Pattern pattern;
Matcher matcher;

final String PASSWORD_PATTERN = "((?=.*\\d).{6,12})";

pattern = Pattern.compile(PASSWORD_PATTERN);
matcher = pattern.matcher(passw_check);

return matcher.matches();
}

public boolean schermnaam_ok(final String scr_name_check){

Pattern pattern;
Matcher matcher;

final String PASSWORD_PATTERN = "(.{5,15})";

pattern = Pattern.compile(PASSWORD_PATTERN);
matcher = pattern.matcher(scr_name_check);

return matcher.matches();
}

//Hoe ga je dit testen?
public void onClickSignUpPage(View view){

String schermnaam = screen.getText().toString().trim();
String emailadres = mail.getText().toString().trim();
String paswoord = pass.getText().toString().trim();

if(TextUtils.isEmpty(schermnaam)){
Toast.makeText(this,"Schermnaam invullen", Toast.LENGTH_SHORT).show();
return;
}

if(TextUtils.isEmpty(emailadres)){
Toast.makeText(this,"Email invullen",Toast.LENGTH_SHORT).show();
return;
}

if(!schermnaam_ok(schermnaam)){
Toast.makeText(this,"schermnaam minstens 5 en maximum 15 tekens", Toast.LENGTH_SHORT).show();
return;
}

if(!paswoord_ok(paswoord)){
Toast.makeText(this,"paswoord tussen 6-12 karakters en minstens 1 cijfer", Toast.LENGTH_SHORT).show();
return;
}

firebaseAuth.createUserWithEmailAndPassword(emailadres.trim(),paswoord)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(SignUpPage.this, "Nieuwe Speler Geregistreerd", Toast.LENGTH_SHORT).show();
}
else {
FirebaseAuthException e = (FirebaseAuthException) task.getException();
Toast.makeText(SignUpPage.this,"Fout in de SignUp"+e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("LoginActivity", "Failed Registration", e);
return;
}
}
});

Intent intent = new Intent(this, SignInPage.class);
startActivity(intent);
}

}

关于java - Firebase 身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49576591/

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