Android Login- Checking If Username And Password Match With Mysql Database
Solution 1:
You do not need to write for each loop.You have to make a GET/POST call to something.com.php and send your username and password to the server.
Then you have to check weather the username and password matches with your database.Write that logic in something.com.php
If it is a match send a success flag to your app as 1 and 0 otherwise.
Parse the success flag in your app and check weather it is 0 or 1.
Based on it let the user login your app.
See:
https://www.simplifiedcoding.net/android-php-mysql-login-tutorial-android-login-app-3/
http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/
Solution 2:
You need to send Login details to server and check on server for success or fail then do as per response in your app Here is brief example of it
- First get user name and password from edit text
StringUserName=EditText_UserName.getText().toString();
StringPassword=EditText_Password.getText().toString();
- Send these Strings to AsyncTask like this
new asynctask().execute(UserName,Password)
- Get Username and Password in doInBackground(String...params)
Phone=params[0];
Password=params[1];
3:Encode Username and password in single string like this
> String data = URLEncoder.encode("UserName", "UTF-8") + "=" +> URLEncoder.encode(UserName, "UTF-8");> data += "&" + URLEncoder.encode("Password", "UTF-8") + "=" + URLEncoder.encode(Password, "UTF-8");4:Now Write data to URL with help of BufferedWriter
URLurl=newURL("http://www.Example.com/Login.php");
HttpURLConnectionconnection= (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
OutputStreamos= connection.getOutputStream();
BufferedWriterwriter=newBufferedWriter(newOutputStreamWriter(os, "UTF-8"));
writer.write(data);
writer.flush();
writer.close();
os.close();
5: Now in Php file compare result with data base and send response back to android app like this
//Get Values first $UserName=$_POST['UserName'];
$Password =$_POST['Password'];
//then compare it in SQL DATABASE$sql = "SELECT * FROM mobile_App WHERE UserName = '$UserName' AND Password = '$Password'";
//Send Response to app if query success$response['status'] = 'SUCCESS';
//else send failed6:Check Response Code in App
int responseCode = connection.getResponseCode();//It will return 200 if Connection Established with server//Get Success String or Fail String By InputStream7: Finally compare string from server Success or Fail and then do further.
Post a Comment for "Android Login- Checking If Username And Password Match With Mysql Database"