Android Login and Registration with Php MySql

Free

Android Login and Registration with Php MySql


PHP Android

Snapshots


MainActivity.Java

package com.trickuweb.mydesign;
		
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.basgeekball.awesomevalidation.AwesomeValidation;
import com.basgeekball.awesomevalidation.ValidationStyle;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    Button requestButton;
    TextView alreadySignin;
    private AwesomeValidation awesomeValidation;
    TextView dataName; // a text field to display the request response
    TextView dataEmail; // a text field where the data to be sent is entered
    TextView dataMobile; // a text field where the data to be sent is entered
    TextView dataPassword; // a text field where the data to be sent is entered
    RequestQueue requestQueue;
    ProgressDialog progressDialog;
    String NameHolder, EmailHolder, MobileHolder, PasswordHolder ;

    // Storing server url into String variable.
    String HttpUrl = "http://192.168.43.30/myphp/signup.php";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        awesomeValidation = new AwesomeValidation(ValidationStyle.BASIC);

        requestButton = (Button) findViewById(R.id.buttonSubmit);
        alreadySignin = (TextView) findViewById(R.id.already_signin);
        requestButton.setOnClickListener(mMyListener);
        alreadySignin.setOnClickListener(mMyListener);

        dataName = (TextView) findViewById(R.id.editTextName);
        dataEmail = (TextView) findViewById(R.id.editTextEmail);
        dataMobile = (TextView) findViewById(R.id.editTextMobile);
        dataPassword = (TextView) findViewById(R.id.editPassword);

        String regexPassword = "(?=.*[a-z])(?=.*[A-Z])(?=.*[\\d])(?=.*[~`!@#\\$%\\^&\\*\\(\\)\\-_\\+=\\{\\}\\[\\]\\|\\;:\"<>,./\\?]).{8,}";
        //adding validation to edittexts
        awesomeValidation.addValidation(this, R.id.editTextName, "^[A-Za-z\\s]{1,}[\\.]{0,1}[A-Za-z\\s]{0,}$", R.string.nameerror);
        awesomeValidation.addValidation(this, R.id.editTextEmail, Patterns.EMAIL_ADDRESS, R.string.emailerror);
        awesomeValidation.addValidation(this, R.id.editTextMobile, "^[2-9]{2}[0-9]{8}$", R.string.mobileerror);
        awesomeValidation.addValidation(this, R.id.editPassword, regexPassword, R.string.passworderror);

        // Creating Volley newRequestQueue .
        requestQueue = Volley.newRequestQueue(MainActivity.this);

        progressDialog = new ProgressDialog(MainActivity.this);

    }

    private View.OnClickListener mMyListener = new View.OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.buttonSubmit:
                    if (awesomeValidation.validate()) {
                        regUser();
                    }
                    break;
                case R.id.already_signin:
                    Intent i = new Intent(getApplicationContext(), LoginActivity.class);
                    startActivity(i);
                    break;
                default:
                    break;
            }
        }
    };
     public void regUser(){
         progressDialog.setMessage("Please Wait, We are Inserting Your Data on Server");
         progressDialog.show();

         NameHolder = dataName.getText().toString().trim();
         EmailHolder = dataEmail.getText().toString().trim();
         MobileHolder = dataMobile.getText().toString().trim();
         PasswordHolder = dataPassword.getText().toString().trim();

         String myurl = "http://192.168.43.30/myphp/signup.php?name=" + NameHolder +
                 "&email=" + EmailHolder + "&mobile="+MobileHolder + "&password=" + PasswordHolder;

         RequestQueue queue = Volley.newRequestQueue(getApplicationContext());

         StringRequest stringRequest = new StringRequest(Request.Method.POST, myurl,
                 new Response.Listener<String>() {
                     @Override
                     public void onResponse(String ServerResponse) {
                         // Hiding the progress dialog after all task complete.
                         progressDialog.dismiss();
                         // Showing response message coming from server.
                         Toast.makeText(MainActivity.this, ServerResponse, Toast.LENGTH_LONG).show();
                     }
                 },
                 new Response.ErrorListener() {
                     @Override
                     public void onErrorResponse(VolleyError volleyError) {
                         // Hiding the progress dialog after all task complete.
                         progressDialog.dismiss();
                         // Showing error message if something goes wrong.
                         Toast.makeText(MainActivity.this, volleyError.toString(), Toast.LENGTH_LONG).show();
                     }
                 });
         queue.add(stringRequest);
     }
}

		

LoginActivity.Java


        
package com.trickuweb.mydesign;

import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.basgeekball.awesomevalidation.AwesomeValidation;
import com.basgeekball.awesomevalidation.ValidationStyle;

public class LoginActivity extends AppCompatActivity {
    Button loginButton;
    TextView alreadySignup;
    private AwesomeValidation awesomeValidation;
    ProgressDialog progressDialog;
    String EmailHolder, PasswordHolder ;
    TextView dataEmail; // a text field where the data to be sent is entered
    TextView dataPassword; // a text field where the data to be sent is entered

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        awesomeValidation = new AwesomeValidation(ValidationStyle.BASIC);

        loginButton = (Button) findViewById(R.id.buttonLogin);
        alreadySignup = (TextView) findViewById(R.id.already_signup);
        loginButton.setOnClickListener(mMyListener);
        alreadySignup.setOnClickListener(mMyListener);

        dataEmail = (TextView) findViewById(R.id.editTextEmail);
        dataPassword = (TextView) findViewById(R.id.editPassword);

        awesomeValidation.addValidation(this, R.id.editTextEmail, Patterns.EMAIL_ADDRESS, R.string.emailerror);
        progressDialog = new ProgressDialog(LoginActivity.this);
    }
    private View.OnClickListener mMyListener = new View.OnClickListener() {
        public void onClick(View v) {
            switch (v.getId() /*to get clicked view id**/) {
                case R.id.buttonLogin:
                    if (awesomeValidation.validate()) {
//                        Toast.makeText(LoginActivity.this, "Checking", Toast.LENGTH_LONG).show();
                        regUser();
                    }
                    break;
                case R.id.already_signup:
                    Intent i = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(i);
                    break;
                default:
                    break;
            }
        }
    };

    public void regUser(){
        progressDialog.setMessage("Please Wait, We are Inserting Your Data on Server");
        progressDialog.show();

        EmailHolder = dataEmail.getText().toString().trim();
        PasswordHolder = dataPassword.getText().toString().trim();

        String myurl = "http://192.168.43.30/myphp/login.php?email=" +
                "&email=" + EmailHolder + "&password=" + PasswordHolder;

        RequestQueue queue = Volley.newRequestQueue(getApplicationContext());

        StringRequest stringRequest = new StringRequest(Request.Method.POST, myurl,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String ServerResponse) {
                        // Hiding the progress dialog after all task complete.
                        progressDialog.dismiss();
                        if (ServerResponse.equals("1")){
                            Toast.makeText(LoginActivity.this, ServerResponse, Toast.LENGTH_LONG).show();
                            Intent i = new Intent(getApplicationContext(), WelcomeActivity.class);
                            startActivity(i);
                        }
                        else {
                            Toast.makeText(LoginActivity.this, ServerResponse, Toast.LENGTH_LONG).show();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        // Hiding the progress dialog after all task complete.
                        progressDialog.dismiss();
                        // Showing error message if something goes wrong.
                        Toast.makeText(LoginActivity.this, volleyError.toString(), Toast.LENGTH_LONG).show();
                    }
                });
        queue.add(stringRequest);
    }
}
		
            

login.php


	<?php

		$con=new mysqli("localhost","root","","signupdb");
		$st_check=$con->prepare("select * from users where email=? and password=?");
		$st_check->bind_param("ss", $_GET["email"],$_GET["password"]);
		$st_check->execute();
		$rs=$st_check->get_result();
		if($rs->num_rows==0)
			echo "0";
		else
			echo "1";
				

signup.php

	<?php

		$con=new mysqli("localhost","root","","signupdb");
		$st_check=$con->prepare("select * from users where mobile=?");
		$st_check->bind_param("s", $_GET["mobile"]);
		$st_check->execute();
		$rs=$st_check->get_result();
		if($rs->num_rows==0)
		{
		$st=$con->prepare("insert into users values(?,?,?,?)");
		$st->bind_param("ssss", $_GET["name"],$_GET["email"],$_GET["mobile"],$_GET["password"]);
		$st->execute();
		echo "successful!";
		}
		else
			echo "User already exists!";

MySQL



		CREATE DATABASE signupdb;


		CREATE TABLE users(
		name VARCHAR(30) NOT NULL,
		email VARCHAR(30) NOT NULL,
		mobile VARCHAR(50) NOT NULL,
		password VARCHAR(50) NOT NULL
		)
            



Watch Android Login and Registration with Php MySql Installation



Related Projects


Recent Comments

Latest Comments section by users