by Esmael Telmosa (7 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 7th March 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Simple log-In program,exclude illegal characters like *,- etc. and unload after 3 tries,if unauthorized user
API Declarations
'Create 2 Command button and 2 textboxes
'CmdOk,CmdCancel name of command button
'txtusername,txtpass name of textboxes
'Create a table named:Users
'Create fields:UserID,UserName and Password
Private Sub Cmdcancel_Click()
Unload Me
End Sub
Private Sub CmdOk_Click()
Dim rsPass As New ADODB.Recordset
Dim SqlPass As String
Static TryCntr As Integer
'SqlPass = "select UserName,Password from Users where Username='" & UN & "' and PassWord='" & PW & "'"
SqlPass = "select User_ID,Password from Users where User_ID='" & Trim(txtUsername.Text) & "' "
With rsPass
.CursorLocation = adUseClient
.Open SqlPass, AdoCon, adOpenForwardOnly, adLockReadOnly, adCmdText
If Not .EOF Or Not .BOF Then
If txtPass.Text = Trim(.Fields!Password) Then
Unload Me
Mainform.Show
Else
MsgBox "Pls. check your pass word", vbExclamation, "Invalid Pass word"
With txtPass
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
TryCntr = TryCntr + 1
If TryCntr = 3 Then Unload Me
End If
Else
MsgBox "Not Found", vbExclamation, "Invalid UserName/PassWord"
TryCntr = TryCntr + 1
If TryCntr = 3 Then Unload Me
End If
.Close
Set .ActiveConnection = Nothing
End With
SqlPass = ""
Set rsPass = Nothing
End Sub
'Call the main form if the user press <esc> key,for bypass bassword demo only.
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then Unload Me: Mainform.Show
End Sub
Private Sub txtPass_Change()
With txtPass
If Len(.Text) > 12 Then
MsgBox "Password must be up to 12 characters only.", vbExclamation, "Log-In"
.Text = Mid(.Text, 1, 12)
SendKeys "{home}+{end}"
End If
End With
End Sub
Private Sub txtPass_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Len(txtPass.Text) > 0 Then CmdOk.SetFocus
End If
End Sub
Private Sub txtUsername_Change()
With txtUsername
If Len(.Text) > 12 Then
MsgBox "User name must be up to 12 characters only.", vbExclamation, "Log-In"
.Text = Mid(.Text, 1, 12)
SendKeys "{home}+{end}"
End If
End With
End Sub
Private Sub txtUsername_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8
Case 13:
If Len(txtUsername.Text) > 0 Then
With txtPass
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
Else
txtUsername.SetFocus
End If
Case 32
Case 65 To 90
Case 97 To 122
Case Else: KeyAscii = 0
End Select
KeyAscii = Asc(UCase(Chr$(KeyAscii)))
End Sub
No comments have been posted about Simple log-In program,exclude illegal characters like *,- etc. and unload after 3 tries,if unauthor. Why not be the first to post a comment about Simple log-In program,exclude illegal characters like *,- etc. and unload after 3 tries,if unauthor.