SIPSorcery.CRM.SugarCRM.SugarHelper.Authenticate C# (CSharp) Method

Authenticate() public method

public Authenticate ( string Username, string Password ) : bool
Username string
Password string
return bool
        public bool Authenticate(string Username, string Password)
        {
            //Create an authentication object
            user_auth user = new user_auth();

            //Set the credentials
            user.user_name = Username;
            user.password = this.computeMD5String(Password);

            //Try to authenticate
            set_entry_result authentication_result = this.sugarClient.login(user, "");

            //Check for errors
            if (Convert.ToInt32(authentication_result.error.number) != 0)
            {
                //An error occured
                this.error = String.Concat(authentication_result.error.name, ": ",
                authentication_result.error.description);

                //Clear the existing sessionId
                this.sessionId = String.Empty;
            }
            else
            {
                //Set the sessionId
                this.sessionId = authentication_result.id;

                //Clear the existing error
                this.error = String.Empty;
            }

            //Return the boolean
            return (this.sessionId != String.Empty);
        }

Usage Example

        public void GetContactsForPhoneNumberUnitTest()
        {
            //Create a new instance of the helper class
            SugarHelper helper = new SugarHelper();

            //Authenticate
            if (helper.Authenticate(m_username, m_password))
            {
                //Get the meetings
                string query = "contacts.phone_work like '%99663311%'";
                //string query = String.Format("SELECT CONCAT(first_name,' ',last_name) AS name FROM contacts WHERE (phone_home LIKE '{0}' OR phone_mobile LIKE '{0}' OR phone_work LIKE '{0}' OR phone_other LIKE '{0}')", "99663311");
                //string query = String.Format("SELECT id FROM contacts WHERE (phone_home = '{0}' OR phone_mobile = '{0}' OR phone_work LIKE '{0}' OR phone_other = '{0}')", "99663311");
                Console.WriteLine(query);
                var contacts = helper.GetContacts("", null, query, "", 0, 100, false);
                Console.WriteLine("Contacts count=" + contacts.result_count + ".");

                foreach (var contact in contacts.entry_list)
                {
                    foreach (var field in contact.name_value_list)
                    {
                        //Console.WriteLine(contact.name_value_list[0] + " " + contact.name_value_list[1]);
                        Console.WriteLine(field.name + ": " + field.value);
                    }
                }
            }
        }
All Usage Examples Of SIPSorcery.CRM.SugarCRM.SugarHelper::Authenticate