For this part, we will make a Login application where we log in based on id...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 + <your first name> (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, Void, Integer>". "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<String, Void, Integer> { 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<String, Void, Integer> { 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 <?php /* open connection to db */ include dbconn.php'; /* get user request */ $id = $ POST["id"]; $password = $ POST["password"]; /* create query */ $query "select * from login where " "id='$id' and ". "password = '$password'"; /* run query */ $res = $conn->query($query); echo $res->num rows; /* close connection */ $conn->close(); ?> 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 + <your first name> (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, Void, Integer>". "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<String, Void, Integer> { 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<String, Void, Integer> { 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 <?php /* open connection to db */ include dbconn.php'; /* get user request */ $id = $ POST["id"]; $password = $ POST["password"]; /* create query */ $query "select * from login where " "id='$id' and ". "password = '$password'"; /* run query */ $res = $conn->query($query); echo $res->num rows; /* close connection */ $conn->close(); ?> 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 + <your first name> (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, Void, Integer>". "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<String, Void, Integer> { 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<String, Void, Integer> { 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 <?php /* open connection to db */ include dbconn.php'; /* get user request */ $id = $ POST["id"]; $password = $ POST["password"]; /* create query */ $query "select * from login where " "id='$id' and ". "password = '$password'"; /* run query */ $res = $conn->query($query); echo $res->num rows; /* close connection */ $conn->close(); ?> 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 + <your first name> (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, Void, Integer>". "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<String, Void, Integer> { 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<String, Void, Integer> { 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 <?php /* open connection to db */ include dbconn.php'; /* get user request */ $id = $ POST["id"]; $password = $ POST["password"]; /* create query */ $query "select * from login where " "id='$id' and ". "password = '$password'"; /* run query */ $res = $conn->query($query); echo $res->num rows; /* close connection */ $conn->close(); ?>
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
Question: Calculate the mass of the liquid for each trial. (Subtract the mass of the empty graduated cylinder from the mass of the graduated cylinder with liquid.) Trial 1 10.6 Trial 2 10.0 Trial 3...
-
Top Light Company uses a perpetual inventory system. The company began 2017 with 1,000 lamps in inventory at a cost of $12 per unit. During 2017, Top Light had the following purchases and sales of...
-
In an emergency stop to avoid an accident, a shoulder-strap seatbelt holds a 60-kg passenger in place. If the car was initially traveling at and came to a stop in 5.5 s along a straight, level road,...
-
What factors provide a lower bound on the period at which the system timer interrupts for preemptive context switching?
-
What type of research did those leading Modify Watches conduct when completing a product/service feasibility analysis and what additional research might the founders have pursued when assessing the...
-
Although the R.U.L.L.C.A. is silent on the allocation of profits and losses among members (for tax purposes), it does provide that if an LLC makes any distribution to its members, the distribution...
-
using the periodic inventory Beginning. Feb. 10 Aug. 21. Problem 6-2A Alternative cost flows-perpetual LO2 eXcel CHECK FIGURES: 1. Ending inventory; a. $35,750; b. $35,107.80; 2. Ending inventory =...
-
1. Please explain the importance of transformation process in manufacturing and service sector. Please provide example to support your answer [10 marks]
-
Once a research endeavor is completed and the investigator reports. What occurred in the study, the Method section is written in Blank Space tense? Once a research endeavor is completed and the...
-
a) Tang is a full-time employee but does some consulting work on the side which often results in a balance payable upon filing his tax return. In 20x7, Tang owed $9,000 on filing. In 20x8, Tang owed...
-
A patient is seen in the office where you are employed. The dentist recommends a treatment plan and offers alternative treatment that includes identification of the risk involved. The patient...
-
Explain the impact on the numerator and denominator for dilutive EPS for both convertible bonds and convertible preferred stock.
-
2. Prepare a table and a graph for a binomial distribution with a) p = 0.2, n = 5 =0.2, n%3D b) p = 0.5, n = 8
-
Wal-Mart is the second largest retailer in the world. The data file on the disk holds monthly data on Wal-Marts revenue, along with several possibly related economic variables. a) Using computer...
-
In Exercises find the area of the region bounded by the graphs of the equations. Use a graphing utility to graph the region and verify your result. y = e, y = 0, x = 0, x = 5
-
An open tank has the shape of a right circular cone (see figure). The tank is 8 feet across the top and 6 feet high. How much work is done in emptying the tank by pumping the water over the top edge?...
-
Find both first partial derivatives. z = ln(x + y)
-
Using data on 1000 home loan borrowers, we estimate the linear probability model where \(D E F A U L T=1\) if the borrower has made a mortgage payment more than 90 days late, \(L T V=100\) (loan...
-
We have \(N=396\) observations on employment at fast-food restaurants in two neighboring states, New Jersey and Pennsylvania. In Pennsylvania, the control group \(d_{i}=0\), there is no minimum wage...
-
A sample of 200 Chicago households was taken to investigate how far American households tend to travel when they take a vacation. Consider the model MILES is miles driven per year, INCOME is measured...
Study smarter with the SolutionInn App