能用數據庫做密碼庫嗎?
這是我曾經編過的一段程序,從MDB數據庫中提取regpass表中的內容,用一個datacombo控件列出常的用戶名供選擇,一個TEXTBOX供用戶輸入密碼,大概思路如此,希望對你有幫助.
_______________________________________________
DimcnnPassAsNewADODB.Connection
DimrstPassAsNewADODB.Recordset
DimstrSQLAsString
DimLoginSucceededAsBoolean
PrivateSubcmdCancel_Click()
LoginSucceeded=False
UnloadMe
EndSub
_________________________________________
PrivateSubcmdOK_Click()
LSize=Len(CombUserName.Text)
IfLSize0Then
User=Left$(CombUserName.Text,LSize)
Else
User=vbNullString
EndIf
IfUser="管理員"Then
Pass=rstPass!Password
IftxtPassword.Text=PassThen
LoginSucceeded=True
Else
MsgBox"無效的密碼,請重試!",vbExclamation vbOKOnly,"登錄"
txtPassword.SetFocus
SendKeys"{Home} {End}"
EndIf
ElseIfUser="普通用戶"Then
User="普通用戶"
LoginSucceeded=True
'在此加入一些限制代碼
UnloadMe
Else
MsgBox"非法用戶!!!",,"登錄"
CombUserName.SetFocus
txtPassword.SelLength=Len(txtPassword.Text)
SendKeys"{Home} {End}"
EndIf
EndSub
___________________________________________________
PrivateSubForm_Load()
DatName=App.Path&"DBNAME.dll"
cnnPass.Provider="microsoft.jet.oledb.3.51"
cnnPass.OpenDatName,"admin"
strSQL="select*fromregpass"
rstPass.CursorLocation=adUseServer
rstPass.OpenstrSQL,cnnPass,adOpenKeyset,adLockReadOnly,adCmdText
WithCombUserName
Set.DataSource=rstPass
.DataField="UserName"
Set.RowSource=rstPass
.ListField="UserName"
.BoundColumn="UserName"
EndWith
CombUserName.Text="管理員"
EndSub
PrivateSubForm_Unload(CancelAsInteger)
IfrstPass.State=adStateOpenThen
rstPass.Close
SetrstPass=Nothing
EndIf
IfcnnPass.State=adStateOpenThen
cnnPass.Close
SetcnnPass=Nothing
EndIf
EndSub->