Discussion Locked

User Login

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How do I code a user login to a program. This program is written with VB6? I want to login as Administrator, Manager, and Writer.

5 replies

by jnlclayton

The code below would reference a form titled frmLogin, with two text boxes and an ADODC.
Public gblnCancel As Boolean
Public strPass As String
Option Explicit

Private Sub Verify_password()
Dim strSQL As String
strPass = txtPassword.Text'You may choose to look into a database for your passwords
'or record them in code, or use sql server or Access
'passwords and pass the password and user name as part
'of your connection string,
'sample below verifies the password from a table in an
'Access database
strSQL = "select * from Pword " _
& "WHERE pword = " & _
Chr(34) & strPass & Chr(34)
ado.RecordSource = strSQL
ado.Refresh

' Or below is how you could pass them to an sql connection'string:
' strPass = txtPassword.Text
' strUID = txtUserName.Text
' strConnStr = "Provider=SQLOLEDB.1; Password=" & strPass & ";" _
' & "User ID=" & strUID _
' & ";Initial Catalog=RS2001;Data Source= " & YourServer & ";" _
' & "Use Procedure for Prepare=1;Auto Translate=True;" _
' & "Packet Size=4096;Workstation ID=" & YourWkStation & ";" _
' & "Use Encryption for Data=False;" _
' & "Tag with column collation when possible=False"

End Sub

Private Subcmdok_Click()
Call Verify_password
If Not ado.Recordset.EOF Then
MsgBox "Login Successful"
End If
gblnCancel = False
frmLogon.Hide
'frmMain.Show
End Sub
Private Sub txtPassword_Change()
If txtUserName.Text <> "" And txtPassword.Text <> "" Then
cmdok.Enabled = True
Else
cmdok.Enabled = False
End If
End Sub
Private Sub txtPassword_Validate(Cancel As Boolean)
If txtPassword = "" Then
MsgBox "A valid password is required"Cancel = True
End If
End Sub

by rsv

HI,
No chance for me to give the answer for your question, b'coz above person already given the correct answer.

GOOD LUCK...:)

This discussion is closed to new replies.