private void Login()
{
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(CheckLogin);
foreach (HtmlElement e in wb.document.All)
{
if (e.Name == "username") e.InnerText = sUser;
if (e.Name == "password") e.InnerText = sPass;
if (e.GetAttribute("value") == "Login") e.InvokeMember("Click");
}
}
The CheckLogin() function checks if the login was successful or not.
private void CheckLogin(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (wb.ReadyState == WebBrowserReadyState.Complete)
{
wb.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(CheckLogin);
if (wb.Url.Equals("http://www.just-a-website.com/error.php"))
{
MessageBox.Show("Login unsuccessful. Please review your login credentials.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
rtb.AppendText(wb.Url.ToString() + "\n");
}
else
{
MessageBox.Show("Login successful.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
rtb.AppendText(wb.Url.ToString() + "\n");
}
}
}
The first page my form navigates to, BEFORE login, is: http://www.just-a-website.com/index.php
If you enter a wrong login on the website, it navigates to: http://www.just-a-website.com/error.php where it says invalid username/password
If the login is correct, it navigates to: http://www.just-a-website.com/welcome.php
I added the line below in my if-else statement to check the CURRENT url whether or not the login was successful.
rtb.AppendText(wb.Url.ToString() + "\n");
Problem: My form does not do the above. For some odd reason, if I use incorrect login details, it shows the error.php page saying invalid username/password, but my form says the login is successful. This is where the line above comes in useful. It writes http://www.just-a-website.com/index.php, but the page is on http://www.just-a-website.com/error.php. Ofcourse it says the login is successful...
A few months ago, I programmed two similar applications. Three weeks ago, both were still working flawless. Because of my current problem, I tested both yesterday, and they are doing the same thing: wrong login details -> login successful ??
Thank you for any help. Desperate...
This post has been edited by skater_00: 01 May 2011 - 08:27 AM

New Topic/Question
Reply




MultiQuote





|