VB问题 判断密码是否正确

来源:百度知道 编辑:UC知道 时间:2024/06/07 13:50:02
Private Sub Form_Load() '设置主要对象的属性

Form1.Caption = "用户身份验证"
Text1.Text = ""
Text1.PasswordChar = "*"
Text1.MaxLength = 7
Text1.Enabled = True

End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim pw As String, i As Integer

If KeyAscii = 13 Then ' 按回车键后进行密码检验
pw = Trim(Text1.Text)
'在本行注释语句下添加相应代码,判断密码是否正确, _
如果输入的密码正确: _
输出“你的口令正确,已通过身份验证”,并且根据输入的密码判断用户的权限 _
如果密码不正确:
n = n + 1 ' n 表示不正确输入的次数 _
然后判断输入错误的次数, _
如果次数为3,那么text1不可用,同时输出"你输入的密码不正确,请查证" _
如果不为3,那么输出"口令不正确,是否重试",如果选择"是",那么可再次输入,选择否,结束程序
End If
End Sub
= =老师要求必须按这个格式写啊,就是在注释那补全,其他的都不行

n = 0
do
if pw=in_array(正确的密码集) then
select case pw
case 类型一:用户权限=类型1
case 类型二:用户权限=类型2
……
end select
msgbox("你的口令正确,已通过身份验证")
return 0
else
n = n + 1
end if
while n<3 and checkdialog("口令不正确,是否重试")
text1.enable = false
msgbox("你输入的密码不正确,请查证")

你要有密码存储地址或者比较的对象
以下是采用数据库验证密码的方法
建议你在数据库中建立2个表 一个为用户帐号,密码,其他信息储存的表,另个为权限表 表头为权限名 有此权限则做标记

Public Cn As New Connection
Private rs As New Recordset

Private Sub Command1_Click()
Dim yonghu_id As String
Dim yonghu_mima As String
Dim aa As New Form2

yonghu_id = Trim(Text1.Text)
yonghu_mima = Text2.Text
call lianjie1
rs.Open "select * from yh where [yonghu_id]='" & yonghu_id & "' and [yonghu_mima]='" & yonghu_mima & "'", Cn, adOpenStatic, adLockOptimistic, adCmdText
If rs.RecordCount