Jump to content

[Resolved] using stringinstr to error check a login


Recommended Posts

Basic goal:

error check and make sure the login to a secure page worked

Initial program starts

goes to the internal web tool we use

calls a login function - tested and that works ok

What I need to do is setup something that if the password is wrong and when the page comes back and says "login incorrect" that it reruns the login segment until the page has another keyword to signify that the login was successful, in this case i'm using the term "MSO" because it's in the first line of the tool once it's logged in and loaded into IE.

So far this is what I have:

; error check login
; read page source
; search for string "incorrect"
; if it returns true - loop back and run the login part again and ask for the password again
; if it returns false(or true for another search criteria) - run the rest of the script

$loginSource = _IEDocReadHTML($oIE)
$searchIncorrect = ("incorrect")
$searchCorrect = ("MSO")
$lose = stringinstr($searchIncorrect, $loginSource)
$win = StringInStr($searchCorrect, $loginSource)

Do

If $lose = True Then
Call("loginGo")
MsgBox(0, "Incorrect", $searchIncorrect)
_IELoadWait($oIE)
EndIf

until $win = True

MsgBox(0, "Correct", $searchCorrectorrect)

Call("bulkReport")

'bulkReport' is just the next function in line to be read after the login is successful.

Any thoughts on why this would NOT work?

The user experience is basically that the login script will run once and if the password is wrong - it doesn't rerun the login script based on the fact that the word 'incorrect' is in the html source at that time. The main page URL does not change unfortunately.

I have tried using just a basic -

if stringinstr("incorrect", $loginsource) = true then

...statement, but this had the same result - the login function runs once, the error checking doesn't seem to work and the script doesn't continue.

Any available thoughts or suggestions on this would be awesome.

thanks in advance.....

,nick

Edited by xeroTechnologiesLLC
Link to comment
Share on other sites

If you've read the forum rules you will have noticed "SPAM tools including instant messenger or forum auto-posters. This includes forum or site auto-login methods".

Even if it's an internal site your IT will not love you for creating an auto-login script - I wouldn't because I'm responsible for IT-security at my company.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

As I know you do not know me from Adam, i can explain it is part of my job in the capacity I do to automate certain processes and functions in our job. The script/program does not auto input a login or password and prompts for both.

I appreciate the reminder to the rules, however, and I apologize if I stepped outside the bounds.

The object was not to create a problem, just ask what the best way to error check a webpage would be.

The solution I have come up with, if anyone wishes to have a method to error check IE automation (not just login) is thus, for what I am trying to do:

$ieTitle = WinGetTitle($oIE)

Do
If $ieTitle = "errorsite" Then
Call("loginFunc")
_IELoadWait($oIE)
EndIf
until $ieTitle = "goodsite"

Again, I apologize, but I do not see how I am breaking the rules by inquiring about error checking when using an IE object and automating through a website.

Addition:

If this is still breaking the rules, please feel free to let me know and I will delete the post - or if you would rather, feel free to delete it.

I have no intentions of causing harm, problems, drama, etc...towards a forum I have found extremely useful and wish no ill will towards.

Thanks.

Edited by xeroTechnologiesLLC
Link to comment
Share on other sites

As I understand the rules: As long as the user enters the password you are fine.

Can you give some more information about how the login works?

Does the user start the AutoIt script and then the script opens the login page?

After the user entered userid/password he clicks the "submit" button?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

user runs the script

prompt comes up for login

input assigned to variable

prompt comes up for password

input assigned to another variable

script loads an IE object and passes the captured input to the tool and then once it goes to the next page (essentially gets logged in) continues through the rest of the script to run a report of various items to find out their status - on / off.

Which, overall i have the process to get the report working just fine - minus being able to hit the OPEN button on the final windows control, but i'm working on that last.

I just need it to check and see if the user input the wrong information, the webpage will load up a red error message (altering the html?) to show "Login Invalid", or Check and see if it proceeded to the next page.

If it proceeded to the next page, where the IE title loads, the loop needs to end and the rest of the script needs to run.

If it did not proceed and errored - the title of the page stays the same - reloop and rerequest the login information again.

Does that make better sense?

What i have above works...sort of.

It seems intermittent though. Sometimes it does loop right, others - not.

Thanks,

Nick.

Link to comment
Share on other sites

It makes sense, yes.

What you describe is site auto-login automation as noted by the forum rules. Why? Because you take userid/password from the user and do the login by your script. As userid/password is stored in a variable it isn't secure any more.

Why can't the user login and then click on a button or a symbol in the systray to start the rest of the automation? So you are save because your script doesn't have to fiddle with userid/password. And the user gets assistence with whatever he needs to do after login.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

We have it this way incase they haven't already logged into the tool. Hopes are that future development of the same tool will integrate with the reporting program we are logging into and it will be all automated once the user logs into windows (ideal scenario).

The other side of the situation still remains though. As the tool goes through pages I still need it to error check and make sure the flow of the script is going according to plan. How is the best way to do that when you know the predictable workflow from page to page?

Checking by ID (what I was trying to do with the login part) seems to work...some of the time, but not 100% of the time.

Link to comment
Share on other sites

disregarding the login part - is there no quick way to error check IE as moves through a process?

I have gone down the path of having the script view the HTML for key words - doesn't seem to work.

Check the IE window name - partially works in an If statement, but doesn't run the login function if it fails as it should.

Link to comment
Share on other sites

Broken down to trying to compare the URLs in the following code:

$readMeh = _IEDocReadHTML("[ACTIVE]")
Do
If $urlItem = "firstlink" Then
Call("firstfunction")
ElseIf $urlitem = "secondlink" Then
Call("secondfunction")
EndIf
until $readMeh = NOT "firstlink"

The problem is still the same. It doesn't appear that the script is understanding the URL changes.

I have tried adding sleeps and waits accordingly.

Still out of ideas.

Anyone have any ideas or optional logic to provide?

Thanks.

edit: corrected code.....

Edited by xeroTechnologiesLLC
Link to comment
Share on other sites

I don't think you're breaking the rules so I'll take a chance that you're not.

It's difficult to help you because you are calling functions which determine the success or failure of the login but you don't show the functions. Referring to your first post, if the function LoginGo doesn't change the variable $win then it will never work, but then if it does change $win why do you set $win first before the loop starts where it will get changed straight away?

So I'm a bit confused. It looks as though you think that setting

$loginSource = _IEDocReadHTML($oIE)

will keep $loginSource up-to-date with any changes in the HTML but in fact you will need to call that line every time you think the HTML has changed.

But I probably misunderstand.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Ah I see.

So when I try to compare page 1's source using the $loginSource variable to page 2's source using the same variable it won't work? I'm guessing because it would hold page 1's source up until I call it to read page 2's then just overwrite it and have nothing to compare to?

I wish I had thought to check that, but being relatively new to programming it didn't even cross my mind...

Thanks for the insight, I will be continuing this project today.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...