VB 6.0 - Code for login form with validation in vb 6.0

Asked By Ravish on 12-Feb-10 01:23 AM
Hi, am working on project which is using VB.I want the source code for login form where user will enter the username & password.The password & username has to be stord in database which access.I also want the validation for it.Please help me as am new to VB.
Sagar P replied to Ravish on 12-Feb-10 01:34 AM
Try this code and work wround it to get result you want;

Private Sub cmdEnter_Click()

Dim strName As String
Dim strPass As String
Dim pesan As String ‘pesan is Indonesian and it is the same with Message in english

strName = txtUsr.Text
strPass = txtPwd.Text

Do Until UsrData.Recordset.EOF
If UsrData.Recordset.Fields("username").Value = strName And UsrData.Recordset.Fields("password").Value = strPass Then
frmEmployee.Show ‘if the login succeed then form that contain employee info shown
Exit Sub

End If


pesan = MsgBox("Invalid password, try again!", vbOKCancel,”Understanding What Is”)
If (pesan = 1) Then
txtName.Text = ""
txtpassword = ""

End If

End Sub

Check out this link as well;
Anoop S replied to Sagar P on 12-Feb-10 11:25 PM

Private Sub cmdOK_Click()
Dim cn As New ADODB.Connection
Dim strCNString As String
Dim rs As New ADODB.Recordset
Dim Txt As String

   On Error GoTo ErrHandler
   'Connect to database
   strCNString = "Data Source=" & App.Path & "\db1.mdb"
   cn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
   cn.ConnectionString = strCNString
   cn.Properties("Jet OLEDB:Database Password") = "jason"
   'Open recordsource
   With rs
       .Open "Select * from Users where Username='" & txtUserName.Text & "' and Password='" & txtPassword.Text & "'", cn, adOpenDynamic, adLockOptimistic
       'Check username and password
       If .EOF Then
           MsgBox "Access Denied...Please enter correct password!", vbOKOnly + vbCritical, "Security Login"
           txtUserName.Text = ""
           txtPassword.Text = ""
           Txt = "" & " " & UCase$(txtUserName.Text) & ""
           MsgBox "Welcome!!!" & Txt, vbOKOnly + vbExclamation, "Security Login"
           Unload Me
       End If
   End With

   Exit Sub

   MsgBox Err.Number & " " & Err.Description, vbCritical, "Login ..."
End Sub
simran replied to Ravish on 17-May-10 11:50 AM
code for login form Please

denn mark replied to Ravish on 12-Mar-11 06:19 PM
Thanks a lot It really helps
manan shah replied to Anoop S on 25-Dec-11 01:19 AM
I want to same code with sql database.
I have registration table.
From which i want just username & password for validatoin.
How can i?
Please give me code if any one know?
Anoop S replied to manan shah on 29-Dec-11 10:59 PM
Try this code

Dim rs As ADODB.Recordset 'rs is the recordset that is used to check the username & password
Dim sql As String 'used to handle the sql statment
Dim sConn As String 'Connection String
Dim iChances As Integer ' 3 Strikes Counter

Private Sub Command1_Click()
    Set rs = New ADODB.Recordset
    'Tell vb what database to use
    sConn = "Ypur connection string"
    'This is where the username and password are checked within the database
    sql = "SELECT * FROM tblLogin WHERE Username ='" & txtUsername.Text & _
    "' AND Password ='" & txtPassword.Text & "'"

    'Open the recordset for use in the login
    rs.Open sql, sConn, adOpenDynamic, adLockReadOnly, adCmdText

    If Not rs.EOF Then
      Form2.Show 'Login was sucessful now show another form
      Unload Me ' Unload this one
      'The login failed
      MsgBox "Wrong username or password", , "Login Error"
      iChances = iChances + 1 ' Another chance gone
      If iChances = 3 Then Unload Me ' All chances gone
    End If
    'Close the recordset
    Set rs = Nothing
End Sub
channaveer sheelwant replied to Ravish on 30-Jul-12 03:36 AM
thank you
channaveer sheelwant replied to Ravish on 30-Jul-12 03:38 AM
please send me the hole project of vb...... with design and source code