function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Avinash Kumar 90Avinash Kumar 90 

Mentioning username / password in code

Hello All,
 Do we need to mention username and password in the code ? I got this sample code from salesforce documentation. 
Any help would be greatly appreciated. I read that if one is using OAuth then user credentials need not be mentioned in the code.

public boolean loginSample() {
   boolean success = false;
   String username = "username";
String password = "password";
String authEndPoint = "https://login.salesforce.com/services/Soap/c/24.0/";

 try {
     ConnectorConfig config = new ConnectorConfig();
      config.setUsername(username);
      config.setPassword(password);       
 
      System.out.println("AuthEndPoint: " + authEndPoint);
      config.setAuthEndpoint(authEndPoint);
 
      connection = new EnterpriseConnection(config);
 
      // Print user and session info
      GetUserInfoResult userInfo = connection.getUserInfo();
      System.out.println("UserID: " + userInfo.getUserId());
      System.out.println("User Full Name: " + userInfo.getUserFullName());
      System.out.println("User Email: " + userInfo.getUserEmail());
      System.out.println();
      System.out.println("SessionID: " + config.getSessionId());
      System.out.println("Auth End Point: " + config.getAuthEndpoint());
      System.out
            .println("Service End Point: " + config.getServiceEndpoint());
      System.out.println();
 
     success = true;
   } catch (ConnectionException ce) {
      ce.printStackTrace();
   }
    return success;
}


Regards,
 Avinash
NagendraNagendra (Salesforce Developers) 
Hi Avinash,

Please check with below link for better understanding of OAuth protocol. Regards,
Nagendra.