|
请问有谁做过MS ACCESS 里的 PASSWORD LOGIN???
[复制链接]
|
|
楼主 |
发表于 11-7-2006 09:29 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 12-7-2006 10:25 AM
|
显示全部楼层
你把IsNull那两个condition用logical or连接起来,像这样:
[size=-1]Private Sub Click_Me_Click()
If IsNull(DLookup("username", "login_table", "[username] = '" & Me.[u-username] & "'")) Or _
IsNull(DLookup("password", "login_table", "[password] = '" & Me.[u-userpass] & "'")) Then
MsgBox "Username and/or password does not match. Try again", vbOKOnly
Else
DoCmd.OpenForm "Main SwitchBoard"
DoCmd.Close acForm, "login_form"
End If
End Sub
上面的代码,还没有compile过,如果有bug。。。自己debug一下。 |
|
|
|
|
|
|
|
楼主 |
发表于 12-7-2006 10:56 AM
|
显示全部楼层
原来还可以用 or_ 的 command 哟~。。。呵呵呵
我也刚刚进来。。。谢谢你先了
呵呵,,可以变得好厉害了。。。。现在我的login form 变得好酷了。。。真的是感激不尽了。。。mee meee
[ 本帖最后由 程家伟 于 12-7-2006 11:03 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 13-7-2006 12:55 PM
|
显示全部楼层
回复 #23 程家伟 的帖子
不用客气。。。:handshake:
其实,programming/coding只要变通一下,就可以很多花样出来了。
用两个 If 也可以。。。再用两个 Not。。。或用两个 Not 和一个 And。。。也可以。
[size=-1]Private Sub Click_Me_Click()
If Not IsNull(DLookup("username", "login_table", "[username] = '" & Me.[u-username] & "'")) Then
If Not IsNull(DLookup("password", "login_table", "[password] = '" & Me.[u-userpass] & "'")) Then
DoCmd.OpenForm "Main SwitchBoard"
DoCmd.Close acForm, "login_form"
Else
MsgBox "Username and/or password does not match. Try again", vbOKOnly
End If
End If
End Sub
[size=-1]Private Sub Click_Me_Click()
If Not IsNull(DLookup("username", "login_table", "[username] = '" & Me.[u-username] & "'")) And _
Not IsNull(DLookup("password", "login_table", "[password] = '" & Me.[u-userpass] & "'")) Then
DoCmd.OpenForm "Main SwitchBoard"
DoCmd.Close acForm, "login_form"
Else
MsgBox "Username and/or password does not match. Try again", vbOKOnly
End If
End Sub
昨天,还有另外看到你发的贴,就一起教你。。。
要解决,字体掉在格子的问题,只需要把它的输入的资料“清空”就可以了。
[size=-1]Private Sub Click_Me_Click()
If IsNull(DLookup("username", "login_table", "[username] = '" & Me.[u-username] & "'")) Or _
IsNull(DLookup("password", "login_table", "[password] = '" & Me.[u-userpass] & "'")) Then
MsgBox "Username and/or password does not match. Try again", vbOKOnly
Me.[u-username] = ""
Me.[u-userpass] = ""
Else
DoCmd.OpenForm "Main SwitchBoard"
DoCmd.Close acForm, "login_form"
End If
End Sub
如果,要让access直接退出,用application.quit应该可以。。。
sub QuitMyProgram
Application.quit
End sub
[ 本帖最后由 meemee 于 13-7-2006 12:57 PM 编辑 ] |
|
|
|
|
|
|
|
楼主 |
发表于 14-7-2006 10:15 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 15-7-2006 06:15 PM
|
显示全部楼层
|
|
|
|
|
|
|
楼主 |
发表于 15-7-2006 06:34 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 25-10-2006 10:25 AM
|
显示全部楼层
你的coding好像有问题哦!
以logik来看,你应该先IsNull u-username和u-userpass后再
check u-username和u-userpass 与 login_table里的username和password的value对比
如一样才能进入
但以你所写的可能会出现问题
如:
在
login_table
username password
admin admin
user user
aaa 123
如果在u-username打admin
u-userpass打123有可能也login成功的哦! |
|
|
|
|
|
|
|
发表于 25-10-2006 11:13 AM
|
显示全部楼层
试试这个看看
If IsNull(Me.[u-username]) Or Me.[u-username] = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.[u-username].SetFocus
Exit Sub
End If
If IsNull(Me.[u-userpass]) Or Me.[u-userpass] = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.[u-userpass].SetFocus
Exit Sub
End If
If Me.[u-userpass] = DLookup("password", "login_table", "[username] = '" & Me.[u-username] & "'") Then
DoCmd.Close acForm, "login_form", acSaveNo
DoCmd.OpenForm "Main SwitchBoard"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.[u-username] = vbNullString
Me.[u-userpass] = vbNullString
Me.[u-username].SetFocus
End If
你试试看
还有你也可以set user max retry warning
module:
Option Compare Database
Public username As Long
login form:
Option Compare Database
Private intLogonAttempts As Integer
Private Sub Login_Click()
在最后放
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "Maximum tried! You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
[ 本帖最后由 stephen0830 于 25-10-2006 12:20 PM 编辑 ] |
|
|
|
|
|
|
|
楼主 |
发表于 27-10-2006 11:06 AM
|
显示全部楼层
回复 #29 stephen0830 的帖子
谢谢你了, stephen兄。。。现在我还在搞着捉虫虫特工队。。。。我们公司中了病毒着。。现在还好了。。。只是剩下server要捉。。。等好了就试试你的方法。。。谢谢 ^_^ |
|
|
|
|
|
|
|
楼主 |
发表于 2-11-2006 10:15 AM
|
显示全部楼层
|
|
|
|
|
|
|
楼主 |
发表于 11-12-2006 01:56 PM
|
显示全部楼层
这段LOGIN FORM有什么办法可以缩短,我对OOP没有什么认识
Private Sub login_Click()
If IsNull(Me.[u-username]) And IsNull(Me.[u-userpass]) Then
MsgBox "You Are Not Enter User Name And PassWord ,Please Try Again.", vbOKOnly
DoCmd.Close acForm, "Login Form"
DoCmd.OpenForm "Login Form"
Else
If Not IsNull(Me.[u-username]) And IsNull(Me.[u-userpass]) Then
MsgBox "You Are Not Enter PassWord ,Please Enter PassWord Again.", vbOKOnly
DoCmd.Close acForm, "Login Form"
DoCmd.OpenForm "Login Form"
Else
If IsNull(Me.[u-username]) And Not IsNull(Me.[u-userpass]) Then
MsgBox "You Are Not Enter You User Name, Please Enter User Name Again.", vbOKOnly
DoCmd.Close acForm, "Login Form"
DoCmd.OpenForm "Login Form"
Else
If Me.[u-username] = "admin" And Me.[u-userpass] = "123456" Then
DoCmd.OpenForm "Main"
DoCmd.Close acForm, "Login Form"
Else
MsgBox "You UserName And PassWord is Invalid, Please Retype Again!", vbOKOnly
DoCmd.Close acForm, "Login Form"
DoCmd.OpenForm "Login Form"
End If
End If
End If
End If
Exit_Login_Click:
Exit Sub
Err_login_Click:
MsgBox Err.Description
Resume Exit_Login_Click
End Sub |
|
|
|
|
|
|
|
发表于 11-12-2006 06:22 PM
|
显示全部楼层
Private Sub login_Click()
Dim valid As Boolean
valid = True
If IsNull(Me.[u-username]) Or IsNull(Me.[u-userpass]) Then
valid = False
End If
If (Me.[u-username]) = "admin" And (Me.[u-userpass]) = "123456" Then
valid = True
Else
valid = False
End If
If Not valid Then
MsgBox "You UserName And PassWord is Invalid, Please Retype Again!", vbOKOnly
Else
DoCmd.OpenForm "Main"
DoCmd.Close acForm, "Login Form"
End If
End Sub |
|
|
|
|
|
|
|
楼主 |
发表于 13-12-2006 01:08 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 13-12-2006 11:12 PM
|
显示全部楼层
原帖由 程家伟 于 13-12-2006 01:08 PM 发表
如果给其他人看到,会不会觉得你偏心(担心着)?有些时候有朋友来放coding请求各位大大来改改。。。很多天了又没有回复的在等待。。到最后会不会被讲呢?
不会... 很多人都懂我不是 gay. |
|
|
|
|
|
|
|
楼主 |
发表于 14-12-2006 05:43 PM
|
显示全部楼层
|
|
|
|
|
|
|
楼主 |
发表于 15-12-2006 10:59 AM
|
显示全部楼层
原帖由 goatstudio 于 11-12-2006 06:22 PM 发表
Private Sub login_Click()
Dim valid As Boolean
valid = True
If IsNull(Me.) Or IsNull(Me.) Then
valid = False
End If
If (Me.) = " ...
原来不能加多几个人的了。。。是给一位user进入罢了
我加了几位user还是不能廖。。。看来要用回 dlook() 了
Private Sub login_Click()
Dim valid As Boolean
valid = True
If IsNull(Me.[u-username]) Or IsNull(Me.[u-userpass]) Then
valid = False
End If
If (Me.[u-username]) = "admin" And (Me.[u-userpass]) = "123456" Then
valid = True
Else
valid = False
End If
If (Me.[u-username]) = "user2" And (Me.[u-userpass]) = "abcdef" Then
valid = True
Else
valid = False
End If
If (Me.[u-username]) = "user3" And (Me.[u-userpass]) = "0987654321" Then
valid = True
Else
valid = False
End If
If Not valid Then
MsgBox "You UserName And PassWord is Invalid, Please Retype Again!", vbOKOnly
Else
DoCmd.OpenForm "Main"
DoCmd.Close acForm, "Login Form"
End If
End Sub |
|
|
|
|
|
|
|
发表于 16-12-2006 11:48 AM
|
显示全部楼层
回复 #37 程家伟 的帖子
可以多做几个user,但是这样的coding做法不好。。。
另一点是,你的logic/algorithm错了。。。
你是用valid这variable来test condition。。。
你先想想看,如果第一个user你已经test成功,你又何必再test user2和user3呢?
你这样做,本来第一个user已经成功,但是,你又连续再test user2和user3那么原来已经success login又变成invalid login。 |
|
|
|
|
|
|
|
发表于 16-12-2006 09:53 PM
|
显示全部楼层
原帖由 程家伟 于 15-12-2006 10:59 AM 发表
原来不能加多几个人的了。。。是给一位user进入罢了
我加了几位user还是不能廖。。。看来要用回 dlook() 了
Private Sub login_Click()
Dim valid As Boolean
valid = True
If ...
你应该用 table 来储存用户, 而不是这样 hardcode. |
|
|
|
|
|
|
|
楼主 |
发表于 18-12-2006 09:41 AM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|