Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ph.activelearning.quicktexter;
- import java.io.BufferedReader;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- /**
- * Created by Admin on 03/17/2017.
- */
- public class Authenticator {
- final String TARGET_URL = "http://www.activelearning.ph/quicktexter/getUserIdByUserName.php";
- public int getUserId(String username, String password) {
- HttpURLConnection urlConnection = null;
- int userId = -1;
- try {
- URL url = new URL(TARGET_URL + "?username=" +
- username + "&password=" + password);
- urlConnection = (HttpURLConnection) url.openConnection();
- if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
- InputStream inStream = urlConnection.getInputStream();
- BufferedReader in = new BufferedReader(
- new InputStreamReader(inStream));
- String inLine = null;
- while ((inLine = in.readLine()) != null) {
- userId = Integer.parseInt(inLine);
- }
- in.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return userId;
- }
- public static void main(String[] args) {
- Authenticator auth = new Authenticator();
- System.out.println("User ID: " + auth.getUserId("a", "a"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement