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
RedSquirrelRedSquirrel 

Login Failure

I recently created a ruby script to login to salesforce and create some objects. It has worked for about a week and all of a sudden the same script will no longer login. It says that I have the wrong name, password, or security token or that I may be locked out.

 

To verify I have the correct security token, I reset it and put it in the script as [password][security token]. Still fails to login. 

 

I tried downloaded the wsdl again to see if the endpoint I need changed. It is still the same.

 

In case of being logged out, I checked and it says a the user will be locked out for 15 minutes. I went to lunch for an hour came back and still failed to login.

 

I don't know what could be going wrong, does anyone have advice to a solution?

Best Answer chosen by Admin (Salesforce Developers) 
RedSquirrelRedSquirrel

I figured it out. Turns out the ruby gem "Savon" that I was using to create the xml soap request would randomly order the xml values in the body. 

 

My Savon Ruby code for the body looked like this:

 

s.body = {:username => myusername, :password => mypassword}

 

You would think that it would create the xml to look like <body><username>myusername</username><password>mypassword</password></body> but it would put password in front sometimes causing the request to fail since username must come first. So even though it worked yesterday, today it decided to change the order of password and username causing it to fail.

 

So the solution was to write the exact xml instead of ruby hash.

 

s.body =  "<username>myusername</username><password>mypassword</password>"

 

Hope that made sense and thanks for everyone's help.

All Answers

SuperfellSuperfell

Login to the web app, and check the entries in login history.

JotmenowJotmenow

Hi there,

 

Are you able to login with same credentials on any other apps like,Data Loader/Sfdc Explorer?

 

Someother things you might want to check:

1.if your admin has setup any profile/IP based login restrictions?

 

Ajay

RedSquirrelRedSquirrel

I am able to login to salesforce.com with my credentials.

 

Oddly enough, it doesn't show the failed login attempts from the ruby app. It does show the login from the web browser though. So it is like the application is not even hitting the login server.

JotmenowJotmenow

Woow!!

 

Do you wanna check the endpoing, username again?

 

I strongly guess username typo

 

Ajay

RedSquirrelRedSquirrel

I figured it out. Turns out the ruby gem "Savon" that I was using to create the xml soap request would randomly order the xml values in the body. 

 

My Savon Ruby code for the body looked like this:

 

s.body = {:username => myusername, :password => mypassword}

 

You would think that it would create the xml to look like <body><username>myusername</username><password>mypassword</password></body> but it would put password in front sometimes causing the request to fail since username must come first. So even though it worked yesterday, today it decided to change the order of password and username causing it to fail.

 

So the solution was to write the exact xml instead of ruby hash.

 

s.body =  "<username>myusername</username><password>mypassword</password>"

 

Hope that made sense and thanks for everyone's help.

This was selected as the best answer
anindaaninda

I was wondering if you could share the sample login script using Savon. Im just getting started with both SF and savon and this would really help me speed things up.

Thanks!

Aninda.