Page 1 of 1

Webbrowser, Remembering Passwords Quite easy really Rate Topic: -----

#1 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Posted 20 April 2010 - 07:41 AM

Ok, Here's another tutorial, and it's on the ability to remember passwords in a VB.NET Browser. It's quite a simple task really.

You need to know:
-How to use settings
-Some knowledge of how HTML works

A little explanation before we get started:

Most HtmlElements (say a textbox, or a button) have certain properties (such as 'vlaue', or 'id'). Normally most password textboxes on webpages have an id such as 'Passwd', 'Pass', or 'Password'. So what we need our application to do is to look for an HtmlElement in the webbrowser document with an id of 'Password', or something like that. Once we have found this element, we can assume that it is the element which we're looking for, we need to set the 'value' attribute (The one which dictates what the element displays) to whatever password we need to remember. The code which I'm going to use to do this isn't the most beautiful in the world, but it works.


[For those who allready have a webbrowser and just want the code for the password setting, please jump to section 2: Setting Password]

1: Creating Your Form

So first of all create a new project, add a textbox, 2 buttons and a webbrowser to your form.

Name the webbrowser wbMain
Name the textbox txtURL
Name the first button btnLoadPassword
Name the second button btnNavigate

Now double click on btnNavigate, and enter this code into the Click event for the button:

wbMain.Navigate(txtUrl.Text)



2: Setting Password

Ok, so now we want to be able to remember passwords.


Go to the application settings in 'My Application' anmd create a StringCollection (System.Collections.Specialized.StringCollection). Set the scope to Application, as we don't want users to modify it. Now set the strings in it to:

password
pass
pwd
passwd

So now go back to the windows forms designer for your main form, and double click 'btnLoadPassword'

Put this code in the Click event for the button:

'Now for each HtmlElemtn in the webbrowser document (it could be a textbox, a button, or whatever)
        For Each ele As HtmlElement In WebBrowser1.document.All
            'For each setting in the list of password field IDs
            For Each item In My.Settings.PasswordFields
                'If the ID of the element matches the the ID stored in the setting
                If ele.GetAttribute("id").ToLower = item.ToLower Then
                    'Get the password from the user
                    Dim Password as String = Inputbox("Please enter your password here")
                    Then set the element's value to the password...                   
                    ele.SetAttribute("value", Password)
                End If
            Next
        Next



Now press F5 to debug, and go to www.gmail.com with your browser. Press the btnLoadPassword, and an inputbox should show, asking for your password. Enter your gmail password, and then press ok. The password box should be set to your password. This works on numerous other websites, such as Facebook and Youtube. It does not work on Hotmail.com, as the id of the password textbox is randomly generated.

So what did we actually do?

So for every HtmlElement in the Webbrowser document
We check if the id attribute of the element is included in the password string array which we made
if that is true we then set its attribute to whatever the user enters into the textbox.
Nothing is done to other elements which are encountered


In this tutorial I only showed you how to fill out the form with a string collected at runtime, but it shouldn't be very difficult to adapt the code so that it loads the password from a file. This tutorial is a basis for a password remembering system in your browser.

I plan to release a turorial in the next few months (it could be weeks or even days, depending on how bored I get) which will show you how to show an information bar on your form asking if a user wants the program to remember their password after they have logged into a website. DreamInCode may not allow this, because it could be used to steal passwords...

Anyway, I hope you enjoyed my tutorial, and feel free to post any questions or bugs down below :)

This post has been edited by Jack Eagles1: 26 April 2010 - 08:12 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Webbrowser, Remembering Passwords

#2 vbConman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-December 11

Posted 31 December 2011 - 01:15 PM

Hi, I copied this project and added to it so it placed my username in the UserName Field.

I wanted to make a project that would
Place my username and password into the correct fields and then click the button to log me in.
I was using this program on gmail to test it out.

I can do the username and password bit, but can't seem to press the log in button. I don't know how to do this can anyone help?

I tried using...
For Each eleme As HtmlElement In WebBrowser1.document.All
            For Each item In My.Settings.LogInFields
                If eleme.GetAttribute("id").ToLower = item.ToLower Then
                    eleme.RaiseEvent("onclick")


To raise the click event in the log in button, but I don't even know if it's possible on gmail or any websites.

Can someone please help.
Thanks in advance.

vbConman.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1