Android Open Source - cellar-communicator Check Pin






From Project

Back to project page cellar-communicator.

License

The source code is released under:

GNU General Public License

If you think the Android project cellar-communicator listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.vinit.orderplacer;
/* ww  w  .  j  a  v  a 2s .  c o m*/
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.util.EntityUtils;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.widget.Button;
import android.widget.Toast;

public class CheckPin extends AsyncTask<Void, Void, String> {

  Context context;
  String pin;
  Button b;
  
  public CheckPin(Context context, String pin, Button b) {
    this.context = context;
    this.pin = pin;
    this.b = b;
  }

  @Override
  protected String doInBackground(Void... arg0) {
    IPGetter get_ip = new IPGetter();
    HttpClient httpClient = new DefaultHttpClient(new BasicHttpParams());
    HttpPost httpPost = new HttpPost(get_ip.getIP() + "verify.php");
    try {
      httpPost.setEntity(new StringEntity(SHA1(pin)));
      HttpResponse httpResponse = httpClient.execute(httpPost);
      HttpEntity entity = httpResponse.getEntity();
      String response = EntityUtils.toString(entity);
      return response;
    } catch (Exception e) {
      e.printStackTrace();
      return "";
    }
  }

  @Override
  protected void onPostExecute(String s) {
    if(s.equals("")) {
      Toast.makeText(context, "Invalid PIN", Toast.LENGTH_SHORT).show();
      b.setEnabled(true);
      return;
    }
    Intent i = new Intent(context, Salesman.class);
    i.putExtra("salesman", s);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
    b.setEnabled(true);
  }

  private String SHA1(String password) {

    MessageDigest mdSha1 = null;
    String hash = "";
    try {
      mdSha1 = MessageDigest.getInstance("SHA1");
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
    try {
      mdSha1.update(password.getBytes("ASCII"));
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
    byte[] data = mdSha1.digest();

    for (int i = 0; i < data.length; i++) {
      hash += Integer.toString((data[i] & 0xff) + 0x100, 16).substring(1);
    }

    return hash;
  }

}




Java Source Code List

com.vinit.orderplacer.CategoryList.java
com.vinit.orderplacer.CheckPin.java
com.vinit.orderplacer.CommentBox.java
com.vinit.orderplacer.CounterOnClickListener.java
com.vinit.orderplacer.DumpJSON.java
com.vinit.orderplacer.IPGetter.java
com.vinit.orderplacer.RetrieveJSON.java
com.vinit.orderplacer.RetrieveSalesmen.java
com.vinit.orderplacer.SalesApp.java
com.vinit.orderplacer.SalesHistory.java
com.vinit.orderplacer.Salesman.java
com.vinit.orderplacer.SecurityPIN.java
com.vinit.orderplacer.SummaryActivity.java