20 thoughts on “Create and Setup a Password Protected Login or Logon using VB 6.0 and VB.NET

  1. Brian

    i created a program that can create account and login account using Visual Basic 6.0 and MS-Access(for database). But, when i create an account, it accepts the data(username and password) even if it is already in the database.

    how can i solve this problem?
    hehehe ^^

  2. Jason Post author

    Hi, I unfortunately do not know much about database access programming.

    But basically what you will want to do is query/search the database to see whether the username and/or the password already exists before adding a new username or password to the database. If it does exist already then you can handle it however you want. Maybe tell the user to put in a different username or something.

    Maybe that will help you. 🙂


  3. boy

    To: Brian

    is this on vb 6.0 or vb 2008?

    on vb 6.0:
    try to use this on your create an account/save button under click event…
    “rs” is the recordset
    “dbcon” is the database connection

    rs.open “select * from tableUSER where USERNAME = ‘” & txtUsername.text & “‘”, dbcon, adopenkeyset, adlockoptimistic
    if rs.recordcount = 1 then
    msgbox(“Username alredy taken… blah blah blah”)
    (code on saving the username/account)
    end if

  4. Boye

    I have user setup table with a vb6 form.
    The table contains; USER_LEVEL, USER_NAME, and PASSWORD.

    I want a vb6 code that will allow users to change their password.
    The user should not be able to make a change if he/she can not remember the old password.

    I need a from from forum members.

  5. red fang

    dim rs as new adodb.recordset
    dim conn as new adodb.connection
    dim sql as string

    sql = “select * from Login” ‘Table
    conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & App.Path & “\BRWSA.mdb;Jet OLEDB:Database Password=Admin;” ‘connection
    rs.Open sql, conn, adOpenStatic, adLockOptimistic

    rs.find “username”=text1.text
    while rs.EOF
    if rs.field!Username=text1.text then
    if rs.field!password=text2.text then
    msgbox”invalid password”,vbcritical,”Password”
    end if
    msgbox”invalid username”,vbcritical,”Username”
    end if

  6. Albert

    hey guys. i’m newby in vb.net. i heard that putting a code behind the forms is not a good and safe way of coding. can zany one please advice me where should i put my code in stead of putting it behind the form…

  7. Jason Post author

    Hi, I’m not sure where you heard that. Or maybe it was misunderstood. In VB.NET even the form class file is like a regular class file. So there is nothing wrong with putting code in the same class that your form uses. I do it all the time and never had a problem.


  8. Hazrat Khan

    Hi dear My name is hazrat khan i am from in afghanistan pleas send me

    the pssword change form coding in visual studio

    I am witing for your email thank you

  9. Nathanel

    There is a situation where the user is able to change the password that will work for the application. do i need to create different interfaces for login and to create new password? how do i code that

  10. Jason Post author

    Hi, You could have a linklabel or button that says click here to change the password, on the main login windows if you want. You could use something like an Inputbox that pops up and allows them to type in a new password.


  11. M.Waleed Khan

    This is really satisfactory info but still confused in few parts. I want to have Login Form Consisting of text boxes for login id and password also buttons for login in reset button for to reset all the text boxes.
    And also I want facility of changing the password/username on a new form in which first the old password/ username is entered and then a change id button is pressed to replace an existing username with new one and same for password

  12. allloj

    Dim rs As ADODB.Recordset

    Private Sub cmdCancel_Click()
    Unload Me
    End Sub

    Private Sub cmdOK_Click()
    Set con = CreateObject(“Adodb.connection”)
    con.Provider = “Microsoft.jet.oledb.4.0”
    con.Open App.Path & “\MainData.mdb”

    Dim strsql As String
    strsql = “Select * from Users”
    Set rs = New ADODB.Recordset
    rs.Open strsql, con, adOpenForwardOnly, adLockOptimistic
    Dim chkPassword

    While Not rs.EOF
    If UCase$(txtUserName) = rs.Fields(“username”) And encrypt(txtPassword) = rs.Fields(“Password”) Then chkPassword = “password”

    If chkPassword = “password” Then
    Call MDIForm1.Show
    Unload Me

    Dim soc As String
    Dim dist As String
    soc = “” & App.Path & “\MainData.mdb”
    dist = “” & App.Path & “\data\MainData.mdb”
    FileSystem.SetAttr soc, vbNormal
    FileSystem.FileCopy soc, dist

    MsgBox “Invalid Password, try again!”, , “PCI Login”
    SendKeys “{Home} {End}”
    End If
    End Sub

    Function encrypt(s As String)
    Dim p As Integer
    Dim i As Integer
    Dim a As String
    a = “”
    For i = 1 To Len(s)
    p = Asc(Mid$(s, i, 1))
    a = a Chr(p Xor 6)
    Next i
    encrypt = a
    End Function

    i lost username and password

  13. nitesh

    how to validate the text that it should contain upparcase lowercase special charecter numeric value as well as not exceed the length 6
    anyone please send the code as u make it its urgent

  14. Jason Post author

    First make the textboxes “.Textlength” property 6 characters long max. That should take care of one problem. Then check the textbox text. Meaning, validating the complete text as upper or lower text in itself. Simply validate the text as is. If the password should be: “MypaSSwOrd” including case. Then try:

    If textbox1.text = “MypaSSwOrd” then
    Messagebox.Show(“Correct Password!”)
    Messagebox.Show(“Password is Not correct!”)
    End If

    That should help you. LMK otherwise. Please take care 🙂


Leave a Reply