0

I have a database in PHPMyAdmin that is connected to a Laravel website and also it is connected to my android app.I can register the user through the laravel website and the password is hashed.But when I try to register through my Android app I can't login into the website because the password is not hashed.How would you hash through android a password?

This is my main activity:

package is.example.artur.adminapp;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class MainActivity extends AppCompatActivity {


    EditText editTextName,editTextEmail,editTextPassword;
    TextView textView;
    private static final String DB_URL = "jdbc:mysql://192.168.1.6/socialmedia_website";
    private static final String USER = "zzz";
    private static final String PASS = "zzz";



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

        textView = (TextView) findViewById(R.id.textView);
        editTextName = (EditText) findViewById(R.id.editTextName);
        editTextEmail = (EditText) findViewById(R.id.editTextEmail);
        editTextPassword = (EditText) findViewById(R.id.editTextPassword);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    public void btnConn(View view) {
        Send objSend = new Send();
        objSend.execute("");


    }

    private class Send extends AsyncTask<String, String, String>

    {
        String msg = "";
        String name = editTextName.getText().toString();
        String email = editTextEmail.getText().toString();
        String password = editTextPassword.getText().toString();

        @Override
        protected void onPreExecute() {
            textView.setText("Please Wait Inserting Data");
        }

        @Override
        protected String doInBackground(String... strings) {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
                if (conn == null) {
                    msg = "Connection goes wrong";
                } else {
                    String query = "Insert INTO users (name,email,password) VALUES('" + name+"','"+email+"','"+password+"')";
                    Statement stmt = conn.createStatement();
                    stmt.executeUpdate(query);
                    msg = "Inserting Successful!!";

                }

                conn.close();

        }

        catch(
        Exception e
        )

        {
            msg = "Connection goes Wrong";
            e.printStackTrace();

        }

        return msg;


    }



@Override
    protected void onPostExecute(String msg) {textView.setText(msg);}



    }




}

Image of database

Image of when I try to login after registration with android app

akhilesh0707
  • 6,709
  • 5
  • 44
  • 51
Lucy
  • 65
  • 2
  • 10
  • 1
    _Just a note:_ You don't have databases _in_ PHPMyAdmin. It's simply a web based application that let's you _manage_ a mysql-database. – M. Eriksson Jul 17 '17 at 14:06
  • m not into android.. but I think you can create a webservice that send a request as jsonm or whatever to the php script – Masivuye Cokile Jul 17 '17 at 14:07
  • @MagnusEriksson Ok ,I ll have that in mind thank you . – Lucy Jul 17 '17 at 14:07
  • You should send the password to an endpoint (which is using SSL, of course) and validate the "raw" password with the hash in PHP. – M. Eriksson Jul 17 '17 at 14:08
  • 1
    Yes You Need to Create API For Passing Some required parameter. – Jaykumar Gondaliya Jul 17 '17 at 14:09
  • 1
    The way the question is closed and pointing to an answer about encrypting passwords is pointing OP in a really bad direction. OP is trying to connect to a DB directly from android which is REALLY BAD. And trying to save a password on a device which is EVEN WORSE. And the password is for a DB which is ... (I have no words). – vlatkozelka Jul 17 '17 at 14:13

0 Answers0