㈠ VB程序编写账号和密码的验证程序
PrivateSubCommand1_Click()
IfIsNumeric(Text1.Text)AndLen(Text1.Text)=6AndText2.Text="good"Then
MsgBox"输入正确,验证通过",vbOKCancel,"验证通过"
Else
IfMsgBox("账号或密码错误",vbRetryCancel,"验证错误")=vbRetryThen
Text1.Text=""
Text2.Text=""
Text1.SetFocus
Else
End
EndIf
EndIf
EndSub
PrivateSubForm_Load()
Text1.PasswordChar="*"
EndSub
㈡ 用VB编写“密码校验”程序的设计
完整代码如下,初始化都已经做好啦,添加控件试试吧:
Dim NCount As Integer
Private Sub Form_Load()
'初始化控件信息
Caption = "密码校验"
Label1.Caption = "请输入密码:"
Text1.Text = ""
Label2.ForeColor = &HFF&
Label2.Alignment = 2
Label2.FontName = "宋体"
Label2.FontSize = 15.75
Label2.AutoSize = True
Label2.Visible = False
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Len(Text1.Text) > 6 And KeyAscii <> 8 And KeyAscii <> 13 Then
KeyAscii = 0
End If
If KeyAscii = 13 And Text1.Text = "1234567" Then
Label2.Caption = "欢迎光临!"
Label2.Visible = True
ElseIf KeyAscii = 13 Then
If NCount <> 1 Then
Label2.Visible = True
Label2.Caption = "密码不符,请再输入一遍!"
Text1.Text = ""
NCount = NCount + 1
Else
Label2.Visible = True
Label2.Caption = "非法用户,请推出程序!"
Text1.Text = ""
Text1.Enabled = False
End If
End If
End Sub
㈢ 用VB语言编制一个帐号与密码的检验程序
Option Explicit
Const MaxLogTimes As Integer = 3
Private Sub cmdCancel_Click()
Dim intResult As Integer
'请求用户确认是否真的退出系统登录
intResult = MsgBox("你选择了退出系统登录,退出将不能启动管理系统!" & vbCrLf & "是否真的退出?", vbYesNo, "登录验证")
If intResult = vbYes Then End '根据用户选择结束应用程序
End Sub
Private Sub cmdOK_Click()
Static intLogTimes As Integer '用于保存用户请求验证的次数
Dim intChecked As Integer, strName As String, strPassword As String
intLogTimes = intLogTimes + 1 '计算登录次数
If intLogTimes > MaxLogTimes Then
'超过允许的登录次数,显示提示信息
MsgBox "你已经超过允许验证次数!" & vbCr & "应用程序将结束!", vbCritical, "登录验证"
End '结束应用程序
Else '进一步验证登录信息的合法性
strName = Trim(txtUserName.Text) '获得输入的用户名
strPassword = Trim(txtPassWord.Text) '获得输入的口令
'检验用户名和口令的合法性,并根据检验返回值执行相应的操作
if(strName ="123456")
if(strPassword="VB6") '口令正确
Unload Me '卸载登录窗体
MsgBox "登录成功,将启动系统程序!", vbInformation, "登录验证"
'通常在此放置显示系统主窗体的语句,例如
'frmMain.Show
else
MsgBox "口令错误,请重新输入!", vbCritical, "登录验证"
txtPassWord.Text = ""
txtPassWord.SetFocus
end if
else '用户不是系统用户
MsgBox "<" & strName & ">不是系统用户,请检查用户名输入是否正确!", vbCritical, "登录验证"
txtUserName.Text = ""
txtPassWord.Text = ""
txtUserName.SetFocus
End If
End If
End Sub
'这是你要的重试 我觉得很没有必要
Private Sub cmdReset_Click()
txtPassWord.Text = ""
txtPassWord.SetFocus
End Sub
说明:
1.账号密码一般是通过数据库调用的,这个程序只是用于娱乐或者测试
2.密码框输出显示请在VB的密码框属性设置里更该,设password为*即可
3.好好读读代码,你就明白代码怎么用了