Solved

Automatically log into a website in webbrowser component

Posted on 2010-08-22
7
541 Views
Last Modified: 2013-11-27
how to auto logon a site in a webbroswer component. What code will auto populate the username, password input boxes and autoclick the login button?

HTML looks like this:-

<form class="ccform" action="login.php" method="post" onsubmit="login();">
<fieldset>
<legend>Login</legend>
<span class="errormsg-inline"></span>
<div class="field-row">
<label for="username">Username</label>
<input type="text" class="field" name="username" id="username" maxlength="16" value="" tabindex="1" />
</div>
<div class="field-row">
<label for="password">Password</label>
<input type="password" class="field" name="password" id="password" maxlength="16" tabindex="2" />
</div>
<div class="field-row">
<input type="hidden" name="direct" id="direct" value="yes" />
<input type="hidden" name="redirect" value="" />
<input type="submit" class="button-inline" name="submit" value="Login" tabindex="3" />
</div>
<div class="field-row">
<p><a href="public.php?mode=forgot" tabindex="4">I forgot my username or password</a></p>
</div>
</fieldset>
</form>
0
Comment
Question by:Oli999
7 Comments
 
LVL 9

Expert Comment

by:Snarfles
ID: 33494895
Is this your own site or someone elses? and how are you opening it?
0
 
LVL 5

Expert Comment

by:kawzaki
ID: 33495040
create a POST request to the http://www.example.com/login.php

and that will do it for you.

details

Basically, you would need to do the following:
1. create a HttpWebRequest object and use HttpWebRequest.Method = "POST".
2. set the Post data to contain your data (username and password).
3. "Post" (i.e. execute and get the response for) the HttpWebRequest.


and you will face cookie not enabled issue, so make sure you enable it as described first line in the code below...

CookieContainer cookies = new CookieContainer();
HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(site);
postRequest.CookieContainer = cookies; // note this
postRequest.Method = "POST";
postRequest.ContentType = "application/x-www-form-urlencoded";
using (Stream stream = postRequest.GetRequestStream())
{
    stream.Write(buffer, 0, buffer.Length);
}


good luck!
0
 
LVL 2

Author Comment

by:Oli999
ID: 33497276
it's someone else's site and I'm just using webbrowser1.navigate to open it
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 33497676
Using IWebBrowser2 is a good idea to do this task.
0
 
LVL 8

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 33497683
0
 
LVL 8

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 33497689
             If u need the complete code, plz let me know!
                                             
0
 
LVL 2

Accepted Solution

by:
Oli999 earned 0 total points
ID: 33575610
Thanks all for your suggestions. Have figured this one out myself now though.

here's how I did it.
If (WebBrowser1.Document.All("username") IsNot Nothing) And (WebBrowser1.Document.All("password") IsNot Nothing) Then
            WebBrowser1.Document.All("username").SetAttribute("value", "username")
            WebBrowser1.Document.All("password").SetAttribute("value", "password")
            For Each element As HtmlElement In WebBrowser1.Document.Body.All
                If element.Name = "submit" Then
                    If element.GetAttribute("value") = "Login" Then
                        element.InvokeMember("click")
                    End If
                End If
            Next
        End If

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now