anybody can give me coding for login? please..

Recommended Answers

All 5 Replies

Private Sub login_Click()
Dim usrname As String
Dim psword As String
Dim usernam As String
Dim pssword As String
Dim Msg As String


datmaklumat.Refresh
usrname = username.Text
psword = password.Text


Do Until datmaklumat.Recordset.EOF
If datmaklumat.Recordset.Fields("Nama Pengguna").Value = usrname And datmaklumat.Recordset.Fields("Kata Laluan").Value = psword Then
LoginForm.Hide
Form1.Show
Exit Sub

Else
datmaklumat.Recordset.MoveNext
End If

Loop

Msg = MsgBox("Invalid password, try again!", vbOKCancel)
If (Msg = 1) Then
LoginForm.Show
username.Text = ""
password.Text = ""

Else
End
End If


End Sub

i want to what the problem of this coding coz, when i enter the invalid username and password,form1 still appeared.

There are four types of login u can code in a vb program. They are :-
1.from table stored in a database
2.from user-defined file
3.from windows registry
4.by fixing some constant value within ur program


If u want to know any of the above send a mail to my email address :-
choudhuryshouvik@gmail.com

forget what i said. use this one :-

'used stuffs :- database(admin.mdb); table(admin); fields(username,password)

Option Explicit

Private Sub cmdlogin_Click()
Dim confirm As Integer

If Trim(txtusername.Text) <> "" And Trim(txtpasswd.Text) <> "" Then
Data1.Refresh

Do Until Data1.Recordset.EOF()
If Data1.Recordset.Fields(0) = Trim(txtusername.Text) And _
Data1.Recordset.Fields(1) = Trim(txtpasswd.Text) Then
Form2.Show
Unload Me
Exit Sub
Else
Data1.Recordset.MoveNext
End If
Loop

confirm = MsgBox("Invalid username and password." & vbCrLf & "Do you want to make another try?", vbQuestion + vbOKCancel, "Admin Error")
If confirm = vbOK Then
txtusername.Text = ""
txtpasswd.Text = ""
txtusername.SetFocus
Else
End
End If
Else
MsgBox "Plz enter admin details first.", vbExclamation, "Sorry!!!"
txtusername.SetFocus
End If
End Sub

Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\admin.mdb"
Data1.RecordSource = "admin"
Data1.Refresh
End Sub

forget what i said. use this one :-

'used stuffs :- database(admin.mdb); table(admin); fields(username,password)

Option Explicit

Private Sub cmdlogin_Click()
Dim confirm As Integer

If Trim(txtusername.Text) <> "" And Trim(txtpasswd.Text) <> "" Then
Data1.Refresh

Do Until Data1.Recordset.EOF()
If Data1.Recordset.Fields(0) = Trim(txtusername.Text) And _
Data1.Recordset.Fields(1) = Trim(txtpasswd.Text) Then
Form2.Show
Unload Me
Exit Sub
Else
Data1.Recordset.MoveNext
End If
Loop

confirm = MsgBox("Invalid username and password." & vbCrLf & "Do you want to make another try?", vbQuestion + vbOKCancel, "Admin Error")
If confirm = vbOK Then
txtusername.Text = ""
txtpasswd.Text = ""
txtusername.SetFocus
Else
End
End If
Else
MsgBox "Plz enter admin details first.", vbExclamation, "Sorry!!!"
txtusername.SetFocus
End If
End Sub

Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\admin.mdb"
Data1.RecordSource = "admin"
Data1.Refresh
End Sub

i was try. but the same situation happened.

'use this one.
'used stuffs : database(login.mdb); table(admin; fields : username,password)

Option Explicit
Dim db As Database, rs As Recordset

Private Sub cmdlogin_Click()
Dim stat As String

If Trim(txtusername.Text) <> "" And Trim(txtpassword.Text) <> "" Then
Set rs = db.OpenRecordset("admin", dbOpenTable)
If rs.RecordCount > 0 Then rs.MoveFirst
Do Until rs.EOF()
If rs("username") = Trim(txtusername.Text) And rs("password") = Trim(txtpassword.Text) Then
stat = "found"
Exit Do
Else
rs.MoveNext
stat = "not found"
End If
Loop
If stat = "found" Then
Unload Me
Form2.Show
ElseIf stat = "not found" Then
MsgBox "The username and password you provided" & vbCrLf & "are not found in the database.", vbApplicationModal + vbExclamation, _
"Invalid LogIn Data"
txtusername.Text = ""
txtpassword.Text = ""
txtusername.SetFocus
End If
Else
MsgBox "Required login parameters are missing.", vbApplicationModal + vbExclamation, "Incomplete Information"
txtusername.SetFocus
End If
End Sub

Private Sub Form_Load()
Set db = OpenDatabase(App.Path & "\login.mdb")
Set rs = db.OpenRecordset("admin", dbOpenTable)
If rs.RecordCount > 0 Then
rs.MoveFirst
ElseIf rs.RecordCount = 0 Then
MsgBox "No login data found." & vbCrLf & "Service currently unavailable.", vbApplicationModal + vbExclamation, "LogIn"
End
End If
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.