. 夜 半 苏 醒 . 
-=学习资料。=-             

首页 >>

 

用MDB文件做密码登陆

   程序阶梯2004-7-19 16:40
用MDB文件做密码登陆

能用数据库做密码库吗?

这是我曾经编过的一段程序,从MDB数据库中提取regpass表中的内容,用一个datacombo控件列出常的用户名供选择,一个TEXTBOX供用户输入密码,大概思路如此,希望对你有帮助.

_______________________________________________

Dim cnnPass As New ADODB.Connection

Dim rstPass As New ADODB.Recordset

Dim strSQL As String

Dim LoginSucceeded As Boolean

Private Sub cmdCancel_Click()

LoginSucceeded = False

Unload Me

End Sub

_________________________________________

Private Sub cmdOK_Click()

LSize = Len(CombUserName.Text)

If LSize 0 Then

User = Left$(CombUserName.Text, LSize)

Else

User = vbNullString

End If

If User = "管理员" Then

Pass = rstPass!Password

If txtPassword.Text = Pass Then

LoginSucceeded = True

Else

MsgBox "无效的密码,请重试!", vbExclamation + vbOKOnly, "登录"

txtPassword.SetFocus

SendKeys "{Home}+{End}"

End If

ElseIf User = "普通用户" Then

User = "普通用户"

LoginSucceeded = True

'在此加入一些限制代码

Unload Me

Else

MsgBox "非法用户!!!", , "登录"

CombUserName.SetFocus

txtPassword.SelLength = Len(txtPassword.Text)

SendKeys "{Home}+{End}"

End If

End Sub

___________________________________________________

Private Sub Form_Load()

DatName = App.Path & "\DBNAME.dll"

cnnPass.Provider = "microsoft.jet.oledb.3.51"

cnnPass.Open DatName, "admin"

strSQL = "select * from regpass "

rstPass.CursorLocation = adUseServer

rstPass.Open strSQL, cnnPass, adOpenKeyset, adLockReadOnly, adCmdText

With CombUserName

Set .DataSource = rstPass

.DataField = "UserName"

Set .RowSource = rstPass

.ListField = "UserName"

.BoundColumn = "UserName"

End With

CombUserName.Text = "管理员"

End Sub

Private Sub Form_Unload(Cancel As Integer)

If rstPass.State = adStateOpen Then

rstPass.Close

Set rstPass = Nothing

End If

If cnnPass.State = adStateOpen Then

cnnPass.Close

Set cnnPass = Nothing

End If

End Sub

标签集:TAGS:
回复Comments()点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}

                                 




 










 




访


 

Design by hecture  Powered by 5dblog