I have included SHA1, and SHA-256 in firebase project.
while fragment is running an Exception Toast Message appears: "This request is missing a valid app indenitier, meaning that neither SafetyNet checks nor reCAPTCHA checks succeeded. Please try again, or checkc the logcat for more details".
Code:
public class VerifyPhoneFragment extends Fragment {
public static String source = null;
PinView pinView;
String phoneNo;
boolean verified = false;
private String VerificationCodSent;
private String CodeEnteredByUser;
public VerifyPhoneFragment() {
// Required empty public constructor
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState){
final NavController navController = Navigation.findNavController(getActivity(), R.id.nav_host_fragment);
final ProgressBar progressBar = view.findViewById(R.id.progress_bar);
ImageView backArrowImageView = view.findViewById(R.id.back_arrow);
TextView backTextView = view.findViewById(R.id.back_text_view);
TextView otpMobileTextView = view.findViewById(R.id.otp_mobile_tv);
Button verifyButton = view.findViewById(R.id.verify_button);
pinView = view.findViewById(R.id.pin_view);
if(source.equals("SignUpFragment")){
phoneNo = "+" + SignUpFragment.mobileTxt;
}
else if(source.equals("LoginFragment")){
phoneNo = "+" + LoginFragment.mobileTxt;
}
else if(source.equals("ForgotPasswordFragment")){
phoneNo = "+" + ForgotPasswordFragment.mobileTxt;
}
otpMobileTextView.setText("Enter OTP sent to Your Phone" + "\n" + phoneNo);
backArrowImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
navController.navigate(R.id.verifyPhone_to_login);
}
});
backTextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
navController.navigate(R.id.verifyPhone_to_login);
}
});
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNo,
60,
TimeUnit.SECONDS,
getActivity(),
new PhoneAuthProvider.OnVerificationStateChangedCallbacks(){
#Override
public void onVerificationCompleted(#NonNull PhoneAuthCredential phoneAuthCredential) {
VerificationCodSent = phoneAuthCredential.getSmsCode();
if(VerificationCodSent != null){
progressBar.setVisibility(View.VISIBLE);
verifyButton.setVisibility(view.INVISIBLE);
PhoneAuthCredential phoneAuthCredential1 = PhoneAuthProvider.getCredential(
VerificationCodSent,
CodeEnteredByUser
);
FirebaseAuth.getInstance().signInWithCredential(phoneAuthCredential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
progressBar.setVisibility(View.GONE);
verifyButton.setVisibility(View.VISIBLE);
if(task.isSuccessful()){
verified = true;
}
else{
Toast.makeText(getContext(), "the Verification Code entered was invalid", Toast.LENGTH_LONG).show();
verified = false;
}
}
});
}
}
#Override
public void onVerificationFailed(#NonNull FirebaseException e) {
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
#Override
public void onCodeSent(#NonNull String VerificationCodeSent, #NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
VerificationCodSent = VerificationCodeSent;
}
}
);
verifyButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(pinView.getText().toString().isEmpty()){
Toast.makeText(getContext(), "Please enter a valid verification code", Toast.LENGTH_LONG).show();
verified = false;
goToAppropriateFragment(source);
}
CodeEnteredByUser = pinView.getText().toString();
if(VerificationCodSent != null){
progressBar.setVisibility(View.VISIBLE);
verifyButton.setVisibility(view.INVISIBLE);
PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.getCredential(
VerificationCodSent,
CodeEnteredByUser
);
FirebaseAuth.getInstance().signInWithCredential(phoneAuthCredential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
progressBar.setVisibility(View.GONE);
verifyButton.setVisibility(View.VISIBLE);
if(task.isSuccessful()){
verified = true;
}
else{
Toast.makeText(getContext(), "the Verification Code entered was invalid", Toast.LENGTH_LONG).show();
verified = false;
}
}
});
}
// afterVerification
goToAppropriateFragment(source);
}
});
}
public void goToAppropriateFragment(String source){
final NavController navController = Navigation.findNavController(getActivity(), R.id.nav_host_fragment);
if(source.equals("SignUpFragment")){
if(verified){
DatabaseHelper databaseHelper = new DatabaseHelper(getContext());
if(databaseHelper.addNewUser()){ // if the user added successfully addUser() returns true
Toast.makeText(getContext(), "You have signed up successfully! you can login", Toast.LENGTH_LONG).show();
// go to LoginFragment
navController.navigate(R.id.verifyPhone_to_login);
}
else{ // to be deleted won't arrive here if email is already used
Toast.makeText(getContext(), "Sorry, Unable to sign you up! Try again later", Toast.LENGTH_LONG).show();
}
}
else {
// Toast.makeText(getContext(), "Sorry, it seems that you have not entered the OTP correctly. Try again", Toast.LENGTH_LONG).show();
// go to SignUpFragment
navController.navigate(R.id.verifyPhone_to_signUp);
}
}
else if(source.equals("LoginFragment")){
if(verified){
// go to MainContentActivity
Toast.makeText(getContext(), "Welcome back " + LoginFragment.fNameTxt + "!", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getContext(), MainContentActivity.class);
startActivity(intent);
}
else {
// Toast.makeText(getContext(), "Sorry, it seems that you have not entered the OTP correctly. Try again", Toast.LENGTH_LONG).show();
// go to LoginFragment
navController.navigate(R.id.verifyPhone_to_login);
}
}
else if(source.equals("ForgotPasswordFragment")){
if(verified){
// go to ResetPasswordFragment
navController.navigate(R.id.verifyPhone_to_resetPassword);
}
else {
Toast.makeText(getContext(), "Sorry, it seems that you have not entered the OTP correctly. Try again", Toast.LENGTH_LONG).show();
// go to LoginFragment
navController.navigate(R.id.verifyPhone_to_login);
}
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_verify_phone, container, false);
}
}
Logcat:
2021-03-30 20:57:21.769 16847-16847/com.example.map_project_v2 E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
2021-03-30 20:57:50.049 16847-16847/com.example.map_project_v2 E/zzf: Problem retrieving SafetyNet Token: 7:
2021-03-30 20:57:51.267 16847-17116/com.example.map_project_v2 E/FirebaseAuth: [GetAuthDomainTask] Error getting project config. Failed with INVALID_CERT_HASH 400
2021-03-30 20:57:51.381 16847-16847/com.example.map_project_v2 E/zzf: Failed to get reCAPTCHA token with error [There was an error while trying to get your package certificate hash.]- calling backend without app verification
2021-03-30 20:57:51.763 16847-16976/com.example.map_project_v2 E/FirebaseAuth: [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17093 null
I was getting the same error and I could solved it with the last two steps of the following (make sure you have covered all of them):
Enable Phone option in Sign-in method under Firebase Authentication
Make sure to download and add the latest google-services.json file in your project
Enable Android Device Verification for your firebase project in https://console.cloud.google.com/
Add library implementation "androidx.browser:browser:1.3.0"
https://developer.android.com/jetpack...
Related
Im working on validation for my login system in android studio java app.
The problem is password validation doesnt work at all. I want that thing to block incorrect password, pass when correct. Changing boolean inside task and passing its value to public boolean should cut off problem, but that's not the case.
activity onViewCreated:
public void onViewCreated(#NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//Firebase synch
inputEmail = (EditText) view.findViewById(R.id.editTextTextEmailAddress);
inputPassword = (EditText) view.findViewById(R.id.editTextNumberPassword);
view.findViewById(R.id.button_second).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
NavHostFragment.findNavController(SecondFragment.this)
.navigate(R.id.action_SecondFragment_to_FirstFragment);
}
});
view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Authentication system
//If not logged and there is not mail in database, create with that parameters.
m_email = inputEmail.getText().toString().trim();
m_pass = inputPassword.getText().toString().trim();
Auth activity = new Auth();
if(!m_email.isEmpty() && !m_pass.isEmpty()) {
//pass if email+password is correct!
activity.SignIn(m_email, m_pass);
Boolean b =activity.valid;
user =mAuth.getCurrentUser();
//deny access to new view
if(!user.isAnonymous()){
Intent intent = new Intent(getContext(), Managment.class);// New activity
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
Snackbar.make(view, "Incorrect auth parameters", Snackbar.LENGTH_LONG)
.setAction(R.string.actionmess, null).show();
}
//empty fields
else{
Snackbar.make(view, "Put all parameters?!", Snackbar.LENGTH_LONG)
.setAction(R.string.actionmess, null).show();
}
}
});
};
auth class. I split it, so code would look better for me to read.
//Sign in#Log in
public void SignIn(String m_email, String m_pass) {
Task<AuthResult> authRegister = mAuth.signInWithEmailAndPassword(m_email, m_pass);
new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful())
valid = TRUE;
if(!task.isSuccessful()) {
try {
throw task.getException();
} catch (FirebaseAuthInvalidUserException e) {
Log.d("Error", "Invalid account");
} catch (FirebaseAuthInvalidCredentialsException e) {
Log.d("Error", "Invalid password");
} catch (FirebaseNetworkException e) {
} catch (Exception e) {
Log.e("error", e.getMessage());
}
Log.w("error", "signInWithEmail:failed",task.getException());
}
valid = FALSE;
}
};
}
I am trying to set up OTP verification
I have already tried many possibilities with the if and else, however, it didn't help out.
public class userLogin extends Activity {
EditText phnNum=null, veri = null;
FirebaseAuth au;
Button forgotpass, login;
PhoneAuthProvider.OnVerificationStateChangedCallbacks otp;
String verifyCode;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userlogin);
login = findViewById(R.id.loginButton);
phnNum = findViewById(R.id.enter_phone);
forgotpass = findViewById(R.id.forgot_pass);
au = FirebaseAuth.getInstance();
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if ((phnNum.getText().toString()).equals("")) {
(Toast.makeText(getApplicationContext(), "Please enter the phone number and proceed to receive an OTP", Toast.LENGTH_SHORT)).show();
}
else{
otp = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(#NonNull PhoneAuthCredential phoneAuthCredential) {
}
#Override
public void onVerificationFailed(#NonNull FirebaseException e) {
}
#Override
public void onCodeSent(#NonNull String s, #NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verifyCode = s;
(Toast.makeText(getApplicationContext(), "The OTP Code has been send, please verify the code", Toast.LENGTH_SHORT)).show();
}
};
}
}
});
}
public void send_sms (View v){
String i = (phnNum.getText()).toString();
PhoneAuthProvider.getInstance().verifyPhoneNumber(i, 60, TimeUnit.SECONDS, this, otp);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent u = new Intent(view.getContext(), otp_verify.class);
startActivity(u);
}
});
}
//SignIn Method
// We will pass value in the method with "PhoneAuthCredential" data-type.
public void SignIn(PhoneAuthCredential credential) {
//" au " is the firebase variable and call the method
au.signInWithCredential(credential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
(Toast.makeText(getApplicationContext(), "You have Sign-In Successfully", Toast.LENGTH_SHORT)).show();
}
else{
(Toast.makeText(getApplicationContext(), "Please try again", Toast.LENGTH_SHORT)).show();
}
}
});
}
}
When I log-in with blank EditText, the if part executes but when I enter the phone number it doesn't execute the else part. I expect the when the user enters their phone number the else part should execute.
final String i = (phnNum.getText()).toString();
if ("".equals(i)) {
(Toast.makeText(getApplicationContext(), "Please enter the phone number and proceed to receive an OTP", Toast.LENGTH_SHORT)).show();
} else {
// 1. prepare callback for async call
otp = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(#NonNull PhoneAuthCredential phoneAuthCredential) {
}
#Override
public void onVerificationFailed(#NonNull FirebaseException e) {
}
#Override
public void onCodeSent(#NonNull String s, #NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verifyCode = s;
(Toast.makeText(getApplicationContext(), "The OTP Code has been send, please verify the code", Toast.LENGTH_SHORT)).show();
Intent u = new Intent(userLogin.this, otp_verify.class);
startActivity(u);
}
};
// 2. execute actual call
PhoneAuthProvider.getInstance().verifyPhoneNumber(i, 60, TimeUnit.SECONDS, userLogin.this, otp);
}
The code snippet prepares callback and uses it on Firebase auth call. When the verification code is actually sent, the onCodeSent called and new activity launched.
I have followed the guideline of firebase docs to implement login into my app but there is a problem while signup, the app is crashing and the catlog showing the following erros :
Process: app, PID: 12830
java.lang.IllegalArgumentException: Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, ortemprary proof.
at com.google.android.gms.common.internal.Preconditions.checkArgument(Unknown Source)
at com.google.firebase.auth.PhoneAuthCredential.<init>(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.getCredential(Unknown Source)
at app.MainActivity.verifyPhoneNumberWithCode(MainActivity.java:132)
at app.MainActivity.onClick(MainActivity.java:110)
at android.view.View.performClick(View.java:4803)
at android.view.View$PerformClick.run(View.java:20102)
at android.os.Handler.handleCallback(Handler.java:810)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5532)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
I've tried to see other code examples but they are simmiler to my code but still my app crashes with the same error.
and this is my code i wrote using the guidline of firebase documents :
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private FirebaseAuth mAuth;
private String mVerificationId;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
Button login,verify,signout;
EditText number;
EditText code;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
login = findViewById(R.id.btnlogin);
verify = findViewById(R.id.btnverify);
signout = findViewById(R.id.btnsignout);
number = findViewById(R.id.editnumber);
code = findViewById(R.id.editcode);
login.setOnClickListener(this);
verify.setOnClickListener(this);
signout.setOnClickListener(this);
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
signInWithPhoneAuthCredential(phoneAuthCredential);
}
#Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(MainActivity.this, "Error" + e.toString(), Toast.LENGTH_SHORT).show();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(MainActivity.this, "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(MainActivity.this, "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCodeSent(String vId, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
Toast.makeText(MainActivity.this, "Code Sent" + vId, Toast.LENGTH_SHORT).show();
number.setText("");
mVerificationId = vId;
}
};
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential phoneAuthCredential) {
mAuth.signInWithCredential(phoneAuthCredential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isComplete()){
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = null;
if (user != null) {
uid = user.getUid();
}
Toast.makeText(MainActivity.this, "Signed In", Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, uid, Toast.LENGTH_SHORT).show();
} else {
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(MainActivity.this, "Invalid Code", Toast.LENGTH_SHORT).show();
}
}
}
});
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnlogin: {
String phonenumber = number.getText().toString();
startPhoneNumberVerification(phonenumber);
}
case R.id.btnverify: {
String vCode = code.getText().toString();
verifyPhoneNumberWithCode(mVerificationId, vCode);
}
case R.id.btnsignout: {
mAuth.signOut();
}
}
}
private void startPhoneNumberVerification(String phoneNumber) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(phoneNumber, 60, TimeUnit.SECONDS, this, mCallbacks);
}
private void verifyPhoneNumberWithCode(String verificationId, String code) {
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
signInWithPhoneAuthCredential(credential);
}
}
The Above code is sending the otp to the given number but it crashes and cat-log shows the error mentioned above.
Please try to help me to figure out what is the error in my code rather referring to other codes.
you are getting number without country code like +91 use with country code or use
String withCountryCode = "+91"+code
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, withCountryCode);
signInWithPhoneAuthCredential(credential);
I'm making social media app that has user profile. I want to save their profile data after they have done their registration. Although the registration is successful, but the user's email and password are not saving in the Firebase database. I've also checked the rules, I use test mode.
Here's my rule:
{
"rules": {
".read": true,
".write": true
}
}
Here's my codes:
public class SignUpActivity extends AppCompatActivity
{
private Button btn_signin,btn_signup;
private EditText inputEmail, inputPassword, inputconPassword;
private ProgressBar progressBar;
private FirebaseAuth auth;
private FirebaseUser firebaseuser;
private static final String PASSWORD_PATTERN ="((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,20})";
private static final String expression = "^[\\w\\.-]+#([\\w\\-]+\\.)+[A-Z]{2,4}$";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
auth = FirebaseAuth.getInstance();
btn_signin = (Button) findViewById(R.id.btn_signin);
btn_signup = (Button) findViewById(R.id.btn_signup);
inputEmail = (EditText) findViewById(R.id.u_email);
inputPassword = (EditText) findViewById(R.id.u_password);
inputconPassword = (EditText) findViewById(R.id.u_conpassword);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
btn_signin.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startActivity(new Intent(SignUpActivity.this, LoginActivity.class));
}
});
btn_signup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String email = inputEmail.getText().toString().trim();
final String password = inputPassword.getText().toString().trim();
if (!validateForm())
{
return;
}
progressBar.setVisibility(View.VISIBLE);
//create user
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(SignUpActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
progressBar.setVisibility(View.GONE);
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful())
{
Toast.makeText(SignUpActivity.this, "Authentication failed." + task.getException(),
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(SignUpActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
firebaseuser = auth.getCurrentUser();
User myUserInsertObj = new User(inputEmail.getText().toString().trim(),inputconPassword.getText().toString().trim());
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Users");
String uid = firebaseuser.getUid();
ref.child(uid).setValue(myUserInsertObj).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task)
{
if(task.isSuccessful())
{
Toast.makeText(SignUpActivity.this, "User data stored.",Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(getApplicationContext(), Main2Activity.class));
}
else
{
Toast.makeText(SignUpActivity.this, "Error.",Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(getApplicationContext(), Main3Activity.class));
}
}
});
}
}
});
}
});
}
private boolean validateForm()
{
boolean valid = true;
String email = inputEmail.getText().toString();
if (TextUtils.isEmpty(email))
{
inputEmail.setError("Required.");
valid = false;
}
String password =inputPassword.getText().toString();
String conpassword = inputconPassword.getText().toString();
if (TextUtils.isEmpty(password))
{
inputPassword.setError("Required.");
valid = false;
}
if (TextUtils.isEmpty(conpassword))
{
inputconPassword.setError("Required.");
valid = false;
}
if(email.length()>0 && password.length()>0 && conpassword.length()>0)
{
if (isEmailValid(email))
{
inputEmail.setError(null);
if (isValidPassword(password))
{
inputPassword.setError(null);
if (isValidPassword(conpassword))
{
inputconPassword.setError(null);
if (password.equals(conpassword))
{
return valid;
}
else
{
Toast.makeText(getApplicationContext(), "Password not matched.Try again.", Toast.LENGTH_SHORT).show();
valid = false;
}
}
else
{
Toast.makeText(getApplicationContext(), "Password must contains minimum 6 characters at least 1 Lowercase, 1 Uppercase and, 1 Number.", Toast.LENGTH_SHORT).show();
valid = false;
}
}
else
{
Toast.makeText(getApplicationContext(), "Password must contains minimum 6 characters at least 1 Lowercase, 1 Uppercase and, 1 Number.", Toast.LENGTH_SHORT).show();
valid = false;
}
}
else
{
Toast.makeText(getApplicationContext(), "Email invalid.", Toast.LENGTH_SHORT).show();
valid = false;
}
}
return valid;
}
public static boolean isEmailValid(String email)
{
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
public static boolean isValidPassword(final String password)
{
Pattern pattern;
Matcher matcher;
pattern = Pattern.compile(PASSWORD_PATTERN);
matcher = pattern.matcher(password);
return matcher.matches();
}
#Override
protected void onResume() {
super.onResume();
progressBar.setVisibility(View.GONE);
}
}
To store the user's email and password after sign up do this:
String email=inputEmail.getText().toString().trim();
String password=inputconPassword.getText().toString().trim();
FirebaseUser currentUser= task.getResult().getUser();
String userid=currentUser.getUid();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users").child(userid);
ref.child("email").setValue(email);
ref.child("password").setValue(password);
Then you will have:
Users
userid
email: email_here
password: password_here
more info here:
https://firebase.google.com/docs/database/android/read-and-write
This answer may give you more insight about how firebase handle auth information (email+password)..
Such information is stored in a separate database so if you want to store user data then you have to do it yourself.
You can find here more details on how to store user data.
Why are you storing plain text password in Firebase? This is a terrible idea. Firebase Auth already hashes and salts your users' passwords. If you ever need to migrate to an external system they provide multiple tools to do so via CLI SDK and Admin SDK.
here is my code for sign up button. it seems like no changes from the previous, but this one works.
btn_signup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String email = inputEmail.getText().toString().trim();
final String password = inputPassword.getText().toString().trim();
if (!validateForm())
{
return;
}
progressBar.setVisibility(View.VISIBLE);
//create user
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(SignUpActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
progressBar.setVisibility(View.GONE);
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (task.isSuccessful())
{
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Users");
firebaseUser = auth.getCurrentUser();
String uid = firebaseUser.getUid();
User my = new User(email,password);
ref.child(uid).setValue(my).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task)
{
if(task.isSuccessful())
{
Toast.makeText(SignUpActivity.this, "Sign Up successfully.",Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(getApplicationContext(), Main2Activity.class));
}
else
{
Toast.makeText(SignUpActivity.this, "Error.",Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(getApplicationContext(), Main3Activity.class));
}
}
});
}
else
{
Toast.makeText(SignUpActivity.this, "Authentication failed." + task.getException(),
Toast.LENGTH_SHORT).show();
}
}
});
}
});
i had created invite users to the app using Facebook in Android, for this used Facebook SDK and added the code given by so peoples, here are my codes
final ImageView facebook1 = (ImageView) findViewById(R.id.facebook1);
facebook1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
// Perform action on click
Facebook facebook1 = new Facebook("APP_ID");
Bundle paramsOut = new Bundle(), paramsIn = this.getIntent().getExtras();
paramsOut.putString("message", paramsIn.getString("message"));
Singlemenuitem.this.mFacebook.dialog(this, "apprequests", paramsOut, new InviteListener(this));
mFacebook.dialog(Singlemenuitem.this, "apprequests", params, new DialogListener() {
public void onComplete(Bundle values) {
final String returnId = values.getString("request");
if (returnId != null) {
Toast.makeText(getApplicationContext(),
"Request sent " + returnId,
Toast.LENGTH_SHORT).show();
}
}
public void onFacebookError(FacebookError error) {}
public void onError(DialogError e) {}
public void onCancel() {}
});
}
but in the place of "InviteListener" getting an error to create class, if the class is created then also getting error. any guidance pls?
Bundle iviteBundleparams = new Bundle();
iviteBundleparams.putString("message",
"invite message");
//TODO:// if you have friend id then you can pass friend id and the request will send this particular friend id
//myIviteBundleparams.putString("to",
friendId);
final ImageView facebook1 = (ImageView) findViewById(R.id.facebook1);
facebook1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
mFacebook.dialog(context,
"apprequests", iviteBundleparams,
new AppRequestsListener());
}
} catch (Exception e) {
// Log.e("VIAMO_FRIENDS", "" + e.toString());
e.printStackTrace();
}
}
});
/*
* callback for the apprequests dialog which sends an app request to user's
* friends.
*/
public class AppRequestsListener extends BaseDialogListener {
/* Default constructor definition */
public AppRequestsListener() {
// TODO Auto-generated constructor stub
}
public void onComplete(Bundle values) {
if (values.size() < 1) {
Toast toast = Toast.makeText(getApplicationContext(),
"App request cancelled", Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(getApplicationContext(),
"App request sent", Toast.LENGTH_LONG);
toast.show();
}
}
public void onFacebookError(FacebookError error) {
Toast.makeText(getApplicationContext(),
"Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT)
.show();
}
public void onCancel() {
Toast toast = Toast.makeText(getApplicationContext(),
"App request cancelled", Toast.LENGTH_SHORT);
toast.show();
}
}
//here mFacebook is your Facebook object
//Facebook mFacebook = new Facebook(APP_ID);