Search

Login and Register with username and password


Login Design Page:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
   android:gravity="center"
    tools:context=".LoginPage">


    <EditText
        android:id="@+id/logphone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Enter your phone no"
        android:inputType="number"
        android:textColor="#e91e63"
        android:textColorHint="#e91e63"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.424" />

    <EditText
        android:id="@+id/logpass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Enter your pasword"
        android:inputType="textPassword"
        android:textColor="#e91e63"
        android:textColorHint="#e91e63"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.593" />

    <TextView
        android:id="@+id/tvstatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#e91e63"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.045"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.842" />
    <Button
        android:id="@+id/btnlogin"
        android:layout_width="358dp"
        android:layout_height="53dp"
        android:backgroundTint="#A1E91E63"
        android:text="Login"
        android:textColor="#FFFFFF"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.461"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.749" />
</LinearLayout>

Register Design Page :-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".RegisterPage">



    <EditText
        android:id="@+id/etName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:backgroundTint="#e91e63"
        android:hint="Name"
        android:inputType="text"
        android:padding="20dp"
        android:textColorHint="#e91e63"
        android:textSize="17sp"
        android:textStyle="bold"
        />

    <EditText
        android:id="@+id/etPhone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/etName"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:backgroundTint="#e91e63"
        android:hint="Phone No"
        android:inputType="number"
        android:padding="20dp"

        android:textColorHint="#e91e63"
        android:textSize="17sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.551"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.562" />

    <EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/etPhone"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:backgroundTint="#e91e63"
        android:hint="Password"
        android:inputType="textPassword"
        android:padding="20dp"

        android:textColorHint="#e91e63"
        android:textSize="17sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.551"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.733" />

    <Button
        android:id="@+id/btnregister"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/etPassword"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:backgroundTint="#e91e63"
        android:padding="17dp"
        android:text="Create Account"
        android:textAllCaps="false"

        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.976" />
</LinearLayout>

Login Java Code :-

package com.example.test_register;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.ValueEventListener;

public class LoginPage extends AppCompatActivity {
    EditText phoneno, pass;
    Button login;
    TextView status;
    String ph,pa;
    static String tmpname;
    //static DatabaseReference databaseCurrentUser;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_page);
       phoneno = (EditText) findViewById(R.id.logphone);
        pass = (EditText) findViewById(R.id.logpass);
        login = (Button) findViewById(R.id.btnlogin);
        status=(TextView)findViewById(R.id.tvstatus);
        status.setText("");
        //databaseCurrentUser= FirebaseDatabase.getInstance().getReference("getUserLogin");

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RegisterPage.getuser();
                ph = phoneno.getText().toString();
                pa = pass.getText().toString();
                RegisterPage.databaseUsers.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        int x = 0;
                        for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
                            MemberReg memberReg = userSnapshot.getValue(MemberReg.class);
                            String dpn = memberReg.getUsername();
                            String dph = memberReg.getPhone();
                            String dpa = memberReg.getPassword();
                            if (dph.equals(ph) && dpa.equals(pa)) {
                              /* {
                                    String id=databaseCurrentUser.push().getKey();
                                    GetUserLogin getUserLogin=new GetUserLogin(dpn,dph,id);
                                    databaseCurrentUser.child(id).setValue(getUserLogin);
                                }*/

                                Intent i=new Intent(LoginPage.this,MainActivity.class);
                                i.putExtra("NAME",dpn);
                                i.putExtra("PHONE",dph);
                                i.putExtra("PASSWORD",dpa);
                                i.putExtra("CALLINGACTIVITY","LoginPage");
                                startActivity(i);
                                x = 1;
                            }
                        }
                        if (x == 0)
                            status.setText("Invalid Credentials");
                    }
                    @Override
                    public void onCancelled(@NonNull DatabaseError databaseError) {

                    }
                });

            }
        });
    }
   /* public void onBackPressed(){
        startActivity(new Intent(LoginPage.this,RegLogChoice.class));
    }*/
}

Register Java Code :-

package com.example.test_register;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class RegisterPage extends AppCompatActivity {
    EditText etname,etphone,etpass;
    Button register;
 static DatabaseReference databaseUsers;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_page);

        databaseUsers= FirebaseDatabase.getInstance().getReference("memberReg");
        register=findViewById(R.id.btnregister);
        etname=findViewById(R.id.etName);
        etphone=findViewById(R.id.etPhone);
        etpass=findViewById(R.id.etPassword);

        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                reg();
            }
        });
    }
    public void reg(){
        String name=etname.getText().toString();
        String phone=etphone.getText().toString();
        String password=etpass.getText().toString();
        if(TextUtils.isEmpty(name)){
            Toast.makeText(this,"Please write your name",Toast.LENGTH_SHORT).show();
        }else if(TextUtils.isEmpty(phone)){
            Toast.makeText(this,"Please write your phone no",Toast.LENGTH_SHORT).show();
        }else if(TextUtils.isEmpty(password)){
            Toast.makeText(this,"Please write your password",Toast.LENGTH_SHORT).show();
        }else{
           String id=databaseUsers.push().getKey();
            MemberReg memberReg=new MemberReg(name,password,phone);
           databaseUsers.child(id).setValue(memberReg);
            Toast.makeText(this,"User registered",Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(getApplicationContext(),LoginPage.class);
            startActivity(intent);
        }
    }
    public static void getuser(){
        databaseUsers=FirebaseDatabase.getInstance().getReference("memberReg");
    }
    }

Mode Java


package com.example.test_register;

public class MemberReg {

    String username, password, phone;
    String id;

    public MemberReg() {
    }

    public MemberReg(String username, String password, String phone) {
        this.username = username;
        this.password = password;
        this.phone = phone;
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}














0 comments

Recent Posts

See All

namefood ingredients app flutter projectFood Donation App College ProjectCollege Android and Website ProjectCollege Leave Management SystemServey for Indian fingerprint unlocking system for

Order any project or you have any idea. Contact - 9306637630. Online Course and Examination Management System Advanced Car & Scooty Training Driving School Management System Advanced Employee Manageme