Advertisement
mhmd320666

Untitled

Jul 9th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.66 KB | None | 0 0
  1. package com.yuhamadgamer.loginwithfire;
  2.  
  3. import android.Manifest;
  4. import android.annotation.SuppressLint;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.pm.PackageManager;
  8. import android.net.wifi.WifiInfo;
  9. import android.net.wifi.WifiManager;
  10. import android.os.Build;
  11. import android.os.Bundle;
  12. import android.provider.Settings;
  13. import android.view.View;
  14. import android.widget.EditText;
  15. import android.widget.TextView;
  16. import android.widget.Toast;
  17.  
  18. import androidx.annotation.NonNull;
  19. import androidx.appcompat.app.AppCompatActivity;
  20. import androidx.core.app.ActivityCompat;
  21.  
  22. import com.google.firebase.database.DataSnapshot;
  23. import com.google.firebase.database.DatabaseError;
  24. import com.google.firebase.database.DatabaseReference;
  25. import com.google.firebase.database.FirebaseDatabase;
  26. import com.google.firebase.database.ValueEventListener;
  27.  
  28. public class MainActivity extends AppCompatActivity {
  29.     EditText userID,pass;
  30.     TextView textView;
  31.     private DatabaseReference ref;
  32.     @Override
  33.     protected void onCreate(Bundle savedInstanceState) {
  34.         super.onCreate(savedInstanceState);
  35.         setContentView(R.layout.activity_main);
  36.         textView = findViewById(R.id.txtview);
  37.         userID =  findViewById(R.id.Username);
  38.         ref = FirebaseDatabase.getInstance().getReference();
  39.         @SuppressLint("HardwareIds") final String ip = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
  40.         textView.setText(ip);
  41.     }
  42.  
  43.     public void btnlogin_Click(View view) {
  44.         final String usrID = userID.getText().toString();
  45.  
  46.       @SuppressLint("HardwareIds") final String ip = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
  47.         try {
  48.            FirebaseDatabase.getInstance().getReference().child("muhamadgamerstrings").addValueEventListener(new ValueEventListener() {
  49.                 @Override
  50.                 public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  51.  
  52.                     for(DataSnapshot ds: dataSnapshot.getChildren()){
  53.  
  54.                         String path = ds.child("userID").getValue(String.class);
  55.                         if(path!=  null && path.equals(usrID )&& ds.child(usrID).child("DeviceID").exists() && ds.child(usrID).child("DeviceID").getValue() ==  ip) {
  56.  
  57.                             Toast.makeText(MainActivity.this,
  58.                                     "login Succesful", Toast.LENGTH_SHORT).show();
  59.                             Intent start = new Intent(MainActivity.this, start.class);
  60.                             startActivity(start);
  61.  
  62.  
  63.                         }
  64.                        else if (ds.child(usrID).child("DeviceID").getValue() == null ){
  65.                             ref.child("muhamadgamerstrings").child(ds.getKey()).child("DeviceID").setValue(ip);
  66.  
  67.  
  68.  
  69.                         }
  70.  
  71.                             else{
  72.                             Toast.makeText(MainActivity.this,
  73.                                     "Error, Different phone", Toast.LENGTH_SHORT).show();
  74.  
  75.                             }
  76.  
  77.                             return;
  78.  
  79.                         }
  80.  
  81.                         Toast.makeText(MainActivity.this,
  82.                                 "Wrong Key",Toast.LENGTH_SHORT).show();
  83.                     }
  84.  
  85.  
  86.  
  87.  
  88.                 @Override
  89.                 public void onCancelled(@NonNull DatabaseError databaseError) {
  90.  
  91.                 }
  92.             });
  93.         }catch (Exception xe){
  94.             Toast.makeText(MainActivity.this,
  95.                     "login error",Toast.LENGTH_SHORT).show();
  96.         }
  97.  
  98.     }
  99.  
  100.  
  101.  
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement