How to hardcode User Name and Password in vb6?
Hard coding user name and password in a system is not a good idea, the reason is, how about if you add new user's and end user's in the system???? , of course you have to re compile your codes, which is not a good idea, Anyway here are some samples of my hard coded user name and password. I only used this codes when I started vb6 programming in college.
The Codes
Option Explicit
Public COUNT1 As Integer
Public LoginSucceeded As Boolean
Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
On Error Resume Next
'check for correct password
If UCase(txtusername.Text) = "ADMINISTRATOR" And UCase(txtpassword) = "ADMIN" _
Or UCase(txtusername.Text) = "ADMIN" And UCase(txtpassword) = "ADMIN123" _
Or UCase(txtusername.Text) = "USER1" And UCase(txtpassword) = "USER1" _
Or UCase(txtusername.Text) = "USER2" And UCase(txtpassword) = "USER2" _
Or UCase(txtusername.Text) = "USER3" And UCase(txtpassword) = "USER3" _
Or UCase(txtusername.Text) = "USER4" And UCase(txtpassword) = "USER4" Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
Me.Hide
'Form4.Show
MainSplash.Show
GoTo JUMP
Else
MsgBox "Invalid Password, try again!", , "Login"
txtpassword.SetFocus
SendKeys "{Home}+{End}"
End If
COUNT1 = COUNT1 + 1
If COUNT1 = 3 Then
MsgBox "Access in not Allowed!"
End
End If
JUMP:
Exit Sub
End Sub
Public COUNT1 As Integer
Public LoginSucceeded As Boolean
Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
On Error Resume Next
'check for correct password
If UCase(txtusername.Text) = "ADMINISTRATOR" And UCase(txtpassword) = "ADMIN" _
Or UCase(txtusername.Text) = "ADMIN" And UCase(txtpassword) = "ADMIN123" _
Or UCase(txtusername.Text) = "USER1" And UCase(txtpassword) = "USER1" _
Or UCase(txtusername.Text) = "USER2" And UCase(txtpassword) = "USER2" _
Or UCase(txtusername.Text) = "USER3" And UCase(txtpassword) = "USER3" _
Or UCase(txtusername.Text) = "USER4" And UCase(txtpassword) = "USER4" Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
Me.Hide
'Form4.Show
MainSplash.Show
GoTo JUMP
Else
MsgBox "Invalid Password, try again!", , "Login"
txtpassword.SetFocus
SendKeys "{Home}+{End}"
End If
COUNT1 = COUNT1 + 1
If COUNT1 = 3 Then
MsgBox "Access in not Allowed!"
End
End If
JUMP:
Exit Sub
End Sub
-In this method the user is given 3 attempts to login if the user fails to enter the correct username and password, the system automatically exit. Here in this method you can add your own, maybe you can add after 3 attempts the pc will automatically shutdown... it's up to you, base on your system security reasoning...
Good Luck!