Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this part, we will make a Login application where we log in based on id and password in login table of MySQL database



imageimageimageimage

For this part, we will make a Login application where we log in based on id and password in "login" table of MySQL database in Internet. Login Application 1:29 LoginDanny ID Enter ID Password Enter Password LOGIN 4 # of records > 0 # of records == 0 1:36 DG LoginDanny ID 1:37 D G LoginDanny test ID Password *** LOGIN Login Status Login success Login success 1 PHP (login.php) HTTP Request (id, password) 2 select query (id, password) query HTTP Response (# of records) records # of records 3 3 test Password .. LOGIN Login Status Login fail Login fail MySQL id password : : : : 1) we type ID and Password, and click "LOGIN" button, which sends id and password to login.php in PHP server. 2) the login.php creates a select query based on the id and password. 3) when # of records are retrieved, login.php checks the # of records, and return the # of records to mobile device. 4) if the # of records is larger than 0, dialog pops up with "login success" message. Otherwise, dialog shows "login fail" message. >>> Project name: Login + (e.g., LoginDanny) - Choose "Empty Activity" template >>> UI requirement: Layout: use RelativeLayout Define and use constants in XML files o dimens.xml layout_space: 20dp (used for padding of layout) themes.xml TextView ID: IblID Text: ID " textSize: 24sp (used for font size of all texts) ID TextView ID: IblPassword EditText ID: inputID Text: (none) Hint: Enter ID Enter ID Password Enter Password Text: Password LOGIN ID: btnLogin Text: LOGIN Button Text - "Password" ID: inputPassword Text: (none) InputType: textPassword Hint: Enter Password >>> Logic codes: We need to create "Task" class to run program in the background. "MainActivity.java" is given for your information, but you need to implement "Task" class. I will give you some information for the "Task" class. I java edu.csustan.cs3810.logindanny MainActivity C Task [MainActivity.java] public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void login (View v) { // get id and password EditText inputID = findViewById(R.id.inputID); String id inputID.getText().toString(); EditText inputPassword = findViewById(R.id.inputPassword); String password = inputPassword.getText().toString(); // run task in background Task task = new Task(this); IblID is pronounced as (el-b-el-ai-D) If not specified explicitly, please use values on your own. } } task.execute(id, password); Errors (in red color) on "Task" and "task.execute()" will be gone after creating Task class at the next step. "login" method is called when clicking "LOGIN" button. "login" method gets id and password, and run program (task) in the background. "login" method provides two arguments (id and password) to the task program. [Task.java] - Task inherits "AsyncTask ". "String": type of input parameters (id and password) "Void": we do not show progress, so the type of progress is Void. "Integer": type of # of records, which is integer. I show you instance variables, constants, constructor, and getURL method for your information. Use them for Task.java. public class Task extends AsyncTask { private Context main; private AlertDialog dialog; wwwwwwwwdww private static final String PROTOCOL = "http://"; private static final String IP ="34.82.21.121"; private static final String FILE_NAME = "login.php"; private static final String HTTP_POST_METHOD = "POST"; private static final int CONNECTION_ERROR public Task(Context main) { = -1; You need to implement methods that are shown as follows. I show you method description and some explanation. You need to implement codes inside methods. O private HttpURLConnection establishConnection() This method establishes TCP connection to server, and returns the connection. private void sendRequest(HttpURLConnection conn, String id, String password) This method sends a request to server using "POST" method through output stream. The code of the request is as follows. String request = "id=" + id + "&password=" + password; O private String getResponse(HttpURLConnection conn) This method gets a response from server through input stream, and returns it. The response is the # of records (by the query based on id and password), and the type of String. (e.g. "1" not integer 1). protected void onPreExecute() " This method creates an alert dialog object. this.main = main; } private String getURL(String fileName) { return PROTOCOL + IP + "/" + fileName; } } Choose "AlertDialog (android.app)" when importing AlertDialog class. public class Task extends AsyncTask { private Context main; private AlertDialog dialog; Import AlertDialog in android.app Class to Im private static AlertDialog (android.app) private static AlertDialog (androidx.appcompat.app) Gradle: andrc O private Integer runQuery(String id, String password) This method gets TCP connection after establishing connection. If connection is null, it returns -1. This method calls send Request() to send request to server. This method calls getResponse() to receive the response from server. The response is assigned to "numOfRecords" int variable. (use Integer.parseInt() to convert String "1" to int 1). Disconnect connection. Last, this method returns the "numOfRecords". O protected Integer doInBackground(String... params) - This method gets two parameters (id and password), and calls runQuery() method whose result is returned. protected void onPostExecute(Integer result) " This method pops up dialog window (with title, "Login Status"). If result is larger than 0, it sets message with "Login success". Otherwise, it sets message with "Login fail"). To show the dialog window, use "show()" method. Appendix: login.php For this part, we will make a Login application where we log in based on id and password in "login" table of MySQL database in Internet. Login Application 1:29 LoginDanny ID Enter ID Password Enter Password LOGIN 4 # of records > 0 # of records == 0 1:36 DG LoginDanny ID 1:37 D G LoginDanny test ID Password *** LOGIN Login Status Login success Login success 1 PHP (login.php) HTTP Request (id, password) 2 select query (id, password) query HTTP Response (# of records) records # of records 3 3 test Password .. LOGIN Login Status Login fail Login fail MySQL id password : : : : 1) we type ID and Password, and click "LOGIN" button, which sends id and password to login.php in PHP server. 2) the login.php creates a select query based on the id and password. 3) when # of records are retrieved, login.php checks the # of records, and return the # of records to mobile device. 4) if the # of records is larger than 0, dialog pops up with "login success" message. Otherwise, dialog shows "login fail" message. >>> Project name: Login + (e.g., LoginDanny) - Choose "Empty Activity" template >>> UI requirement: Layout: use RelativeLayout Define and use constants in XML files o dimens.xml layout_space: 20dp (used for padding of layout) themes.xml TextView ID: IblID Text: ID " textSize: 24sp (used for font size of all texts) ID TextView ID: IblPassword EditText ID: inputID Text: (none) Hint: Enter ID Enter ID Password Enter Password Text: Password LOGIN ID: btnLogin Text: LOGIN Button Text - "Password" ID: inputPassword Text: (none) InputType: textPassword Hint: Enter Password >>> Logic codes: We need to create "Task" class to run program in the background. "MainActivity.java" is given for your information, but you need to implement "Task" class. I will give you some information for the "Task" class. I java edu.csustan.cs3810.logindanny MainActivity C Task [MainActivity.java] public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void login (View v) { // get id and password EditText inputID = findViewById(R.id.inputID); String id inputID.getText().toString(); EditText inputPassword = findViewById(R.id.inputPassword); String password = inputPassword.getText().toString(); // run task in background Task task = new Task(this); IblID is pronounced as (el-b-el-ai-D) If not specified explicitly, please use values on your own. } } task.execute(id, password); Errors (in red color) on "Task" and "task.execute()" will be gone after creating Task class at the next step. "login" method is called when clicking "LOGIN" button. "login" method gets id and password, and run program (task) in the background. "login" method provides two arguments (id and password) to the task program. [Task.java] - Task inherits "AsyncTask ". "String": type of input parameters (id and password) "Void": we do not show progress, so the type of progress is Void. "Integer": type of # of records, which is integer. I show you instance variables, constants, constructor, and getURL method for your information. Use them for Task.java. public class Task extends AsyncTask { private Context main; private AlertDialog dialog; wwwwwwwwdww private static final String PROTOCOL = "http://"; private static final String IP ="34.82.21.121"; private static final String FILE_NAME = "login.php"; private static final String HTTP_POST_METHOD = "POST"; private static final int CONNECTION_ERROR public Task(Context main) { = -1; You need to implement methods that are shown as follows. I show you method description and some explanation. You need to implement codes inside methods. O private HttpURLConnection establishConnection() This method establishes TCP connection to server, and returns the connection. private void sendRequest(HttpURLConnection conn, String id, String password) This method sends a request to server using "POST" method through output stream. The code of the request is as follows. String request = "id=" + id + "&password=" + password; O private String getResponse(HttpURLConnection conn) This method gets a response from server through input stream, and returns it. The response is the # of records (by the query based on id and password), and the type of String. (e.g. "1" not integer 1). protected void onPreExecute() " This method creates an alert dialog object. this.main = main; } private String getURL(String fileName) { return PROTOCOL + IP + "/" + fileName; } } Choose "AlertDialog (android.app)" when importing AlertDialog class. public class Task extends AsyncTask { private Context main; private AlertDialog dialog; Import AlertDialog in android.app Class to Im private static AlertDialog (android.app) private static AlertDialog (androidx.appcompat.app) Gradle: andrc O private Integer runQuery(String id, String password) This method gets TCP connection after establishing connection. If connection is null, it returns -1. This method calls send Request() to send request to server. This method calls getResponse() to receive the response from server. The response is assigned to "numOfRecords" int variable. (use Integer.parseInt() to convert String "1" to int 1). Disconnect connection. Last, this method returns the "numOfRecords". O protected Integer doInBackground(String... params) - This method gets two parameters (id and password), and calls runQuery() method whose result is returned. protected void onPostExecute(Integer result) " This method pops up dialog window (with title, "Login Status"). If result is larger than 0, it sets message with "Login success". Otherwise, it sets message with "Login fail"). To show the dialog window, use "show()" method. Appendix: login.php

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Calculus

Authors: Ron Larson, Bruce H. Edwards

10th Edition

1285057090, 978-1285057095

More Books

Students also viewed these Programming questions

Question

Find both first partial derivatives. z = ln(x + y)

Answered: 1 week ago