Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8429719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:24:51+00:00 2026-06-10T05:24:51+00:00

I have tried to Login Vtiger from my Android Application.I got Challenge token successfully

  • 0

I have tried to Login Vtiger from my Android Application.I got Challenge token successfully and concodinate that challenge token with access key(taken from my account preferences). Then convert to MD5 string.

My Challenge URL:

http://mysite/vtigerCRM510-RC/vtigerCRM/webservice.php?operation=getchallenge&username=Manager

Challenge Response:

{"success":true,"result":{"token":"4ff555f87eece","serverTime":1341478392,"expireTime":1341478692}}

Login URL:

http://mysite/vtigerCRM510-RC/vtigerCRM/webservice.php?operation=login&username=Manager&accesskey=976b9571ff3ff92b7786da17125ac37c

Login Response:

{"success":false,"error":{"code":"INVALID_AUTH_TOKEN","message":"Specified token is invalid or expired"}}

Also I have a doubt, In Android I used AsyncTask for Http Operation.Two Asynctask used.Fisrt one for get Challenge token and using this token done second Async task for Login. Is it correct way? My Android code is below.

My Android Code:

public class GetChallengeActivity extends Activity {
    private TextView textView;
    private static final String USER_NAME="Manager";
    private static final String ACCESS_KEY="myaccesskey"; //taken from preferences

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void postData(View view)
    {
        textView=(TextView) findViewById(R.id.resulttext);

        ConnectivityManager conmgr=(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkinfo=conmgr.getActiveNetworkInfo();
        Log.i(null, "Network Info-->"+networkinfo.toString());
        if(networkinfo!=null && networkinfo.isConnected())
        {
            //Network Available.
            //Toast.makeText(getApplicationContext(), "Network available", Toast.LENGTH_LONG).show();
            Log.i(null, "Network Available");
            textView.setText("Network Available");
            String url="http://mysite/vtigerCRM510-RC/vtigerCRM/webservice.php?operation=getchallenge&username="+USER_NAME+"";
            Log.i(null,"Challenge URL-->"+url);
            new ServerCommunication().execute(url);
        }
        else
        {
            //Network not Available
            Log.i(null, "Network Not Available");
            Toast.makeText(getApplicationContext(), "Network Not available", Toast.LENGTH_LONG).show();
            textView.setText("Network Not Available");
        }
    }

    private class ServerCommunication extends AsyncTask<String,String,String>
    {
        @Override
        protected String doInBackground(String... urls) {
            Log.i(null, "Doing in Background");
            try {
                return postToServer(urls[0]);
            }catch (IOException e) {
                Log.i(null, "Unable to retrieve web page. URL may be invalid.");
                return "Unable to retrieve web page. URL may be invalid.";

            }
        }

        @Override
        protected void onPostExecute(String result)
        {
            Log.i(null, "onPostExecute");
            Log.i(null, result);
            textView.setText(result);
        }

        private String postToServer(String string) throws IOException{
            Log.i(null, "post2Server");
            InputStream is = null;
            // Only display the first 500 characters of the retrieved web page content.
            int len = 500;

            try {
                    URL url = new URL(string);
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setReadTimeout(10000 /* milliseconds */);
                    conn.setConnectTimeout(15000 /* milliseconds */);
                    conn.setRequestMethod("GET");
                    conn.setDoInput(true);

                    // Starts the query
                    conn.connect();
                    int response = conn.getResponseCode();
                    is = conn.getInputStream();

                    // Convert the InputStream into a string
                    String contentAsString = readIt(is, len);
                    Log.i(null,contentAsString);

                   String result="";
                    try {
                            JSONObject jsondata=new JSONObject(contentAsString);

                            String outcomesrf=jsondata.getString("success");
                            Log.i(null, "OutCome---->"+outcomesrf);
                            if(outcomesrf=="false")
                            {
                                JSONObject jsonobj2=jsondata.getJSONObject("error");
                                result=jsonobj2.getString("message");
                                Log.i(null,"Error-->errorMessage---->"+result);
                            }
                            else
                            {
                                JSONObject jsonobj3=jsondata.getJSONObject("result");
                                result=jsonobj3.getString("token");
                                Log.i(null,"Success-->Token---->"+result);
                                Log.i(null,"-->MD5Hash("+result+ACCESS_KEY+")");
                                String generatedkey=MD5_Hash(result+ACCESS_KEY);
                                Log.i(null,"Key-->"+generatedkey);
                                String loginurl="http://mysite/vtigerCRM510-RC/vtigerCRM/webservice.php?operation=login&username="+USER_NAME+"&accesskey="+generatedkey+"";
                                Log.i(null,"Login URL-->"+loginurl);
                                new LoginCommunication().execute(loginurl);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                            Log.i(null,"At Json "+e.toString());
                        }
                    return result;
                }
            finally {
                    if (is != null) {
                        is.close();
                    } 
                }
        }

        // Reads an InputStream and converts it to a String.

    }

    private class LoginCommunication extends AsyncTask<String,String,String>
    {
            @Override
            protected String doInBackground(String... urls) {
                Log.i(null, "Login Posting in Background");
                try {
                    return loginToServer(urls[0]);
                }catch (IOException e) {
                    Log.i(null, "Unable to retrieve web page. URL may be invalid.");
                    return "Unable to retrieve web page. URL may be invalid.";
               }
            }

            @Override
            protected void onPostExecute(String result)
            {
                Log.i(null, "LoginonPostExecute");
                Log.i(null, result);
                textView.setText(result);
            }

             private String loginToServer(String string) throws IOException{
                Log.i(null, "loginToServer");
                InputStream is = null;
                int len = 500;

                try {
                        URL url = new URL(string);
                        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                        conn.setReadTimeout(10000 /* milliseconds */);
                        conn.setConnectTimeout(15000 /* milliseconds */);
                        conn.setRequestMethod("POST");
                        conn.setDoInput(true);
                        conn.setDoOutput(true);

                        // Starts the query
                        conn.connect();
                        int response = conn.getResponseCode();
                        is = conn.getInputStream();

                        // Convert the InputStream into a string
                        String contentAsString = readIt(is, len);
                        Log.i(null,contentAsString);

                       String result1="";
                       String result2="";

                        try {
                                JSONObject jsondata=new JSONObject(contentAsString);

                                String outcomesrf=jsondata.getString("success");
                                Log.i(null, "Login OutCome---->"+outcomesrf);
                                if(outcomesrf=="false")
                                {
                                    JSONObject jsonobj2=jsondata.getJSONObject("error");
                                    result1=jsonobj2.getString("message");
                                    Log.i(null,"Error-->errorMessage---->"+result1);
                                }
                                else
                                {
                                    JSONObject jsonobj3=jsondata.getJSONObject("result");
                                    result1=jsonobj3.getString("sessionName");
                                    Log.i(null,"Success-->sessionName---->"+result1);

                                    JSONObject jsonobj4=jsondata.getJSONObject("result");
                                    result2=jsonobj4.getString("userId");
                                    Log.i(null,"Success-->userId---->"+result2);

                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                                Log.i(null,"At Json "+e.toString());
                            }
                        String result="sessionName"+result1+" userId"+result2;
                        return result;
                    }
                finally {
                        if (is != null) {
                            is.close();
                        } 
                    }
            }
        }

        public String readIt(InputStream stream, int len) throws IOException, UnsupportedEncodingException {
            Reader reader = null;
            reader = new InputStreamReader(stream, "UTF-8");        
            char[] buffer = new char[len];
            reader.read(buffer);
            return new String(buffer);
        }

        public static String MD5_Hash(String s) {
            MessageDigest m = null;

            try {
                    m = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException e) {
                    e.printStackTrace();
            }

            m.update(s.getBytes(),0,s.length());
            String hash = new BigInteger(1, m.digest()).toString(16);
            return hash;
        }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:24:53+00:00Added an answer on June 10, 2026 at 5:24 am

    In your PostToServer, the accesskey verb should be with a upper k (accessKey)

    String loginurl="http://mysite/vtigerCRM510-RC/vtigerCRM/webservice.php?operation=login&username="+USER_NAME+"&accessKey="+generatedkey+"";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Silverlight business application, that require the user to login, and
Hello I have tried to post a tweet from my application. When I press
My problem is that I have successfully login to my Rail sever with HTTP
I have tried several ways to login to a website through java. I have
I have tried so many ways but failed to logged in purevolume.com programmatically! login
I have tried to set up a login page, but when I try to
I have a login form as below, I have tried doing this by onkeydown
I have a function in my login form that checks if the email and
I tried to use the query outside of the database. That is, without login
I have tried to login my server with some fields like username, password, latitude,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.