【发布时间】:2019-10-03 20:59:22
【问题描述】:
我正在尝试将字符串值从一种形式传递到另一种形式。我的第一个表单是“frmLogin”,其中包含用户 ID“strId”和密码“strPassword”(它只是一个常规登录表单)。我试图打开并将字符串传递给的表单是“frmProfile1”。从 frmProfile1,Profile1 用户将文档分配给在 Access 中存储为记录的 Profile2 用户。这些记录将包含分配文档的 Profile1 用户的 ID,因此将 strId 的值从 frmLogin 传递到 frmProfile1 非常重要。
'Project:
'Form: Login Form (frmLogin)
'Author: Nathan Willett
'Created: 9/10/19
'Current Version: 1.0 - 9/10/19
Option Compare Database
Option Explicit
Public strProfile, strId, strPassword As String
'On 'Button Ok' click, perform the following
Public Sub btnLogin_Click()
'If ID Login Box is left blank, display "Please enter Login ID"
If IsNull(Me.txtId) Then
MsgBox "Please enter Login ID", vbInformation, "Login Error"
Me.txtId.SetFocus
Exit Sub
'If Password Box is left blank, display "Please enter Password"
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Password", vbInformation, "Login Error"
Me.txtPassword.SetFocus
Exit Sub
End If
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblUserList", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "fldId='" & Me.txtId & "'"
'If txtID value does not equal fldId, prompt the user
If rs.NoMatch = True Then
MsgBox "Incorrect Login ID. Please try again.", vbInformation, "Login Error"
Me.txtId.SetFocus
Exit Sub
End If
'If txtPassword value does not equal fldPassword, prompt the user
If rs!fldPassword <> Me.txtPassword Then
MsgBox "Incorrect Password. Please try again.", vbInformation, "Login Error"
Me.txtId.SetFocus
Exit Sub
End If
'Look up the users profile version from tblUserList
strProfile = DLookup("fldPosId", "tblUserList", "fldId='" & Me.txtId.Value & "'")
strId = rs!fldId
strPassword = rs!fldPassword
'Open the corresponding profile form
Select Case strProfile
Case "Profile1"
DoCmd.OpenForm "frmProfile1"
Case "Profile2"
DoCmd.OpenForm "frmProfile2"
Case "Profile3"
DoCmd.OpenForm "frmProfile3"
Case "Profile5"
DoCmd.OpenForm "frmProfile4"
End Select
DoCmd.Close acForm, "frmLogin"
End Sub
'On 'Button Cancel' click, close the program
Private Sub btnCancel_Click()
DoCmd.Close acForm, "frmLogin"
End Sub
'Project:
'Form: frmProfile1
'Author: Nathan Willett
'Created: 9/21/19
'Current Version: 1.0 9/21/19
Option Compare Database
Option Explicit
Dim db As Database
Dim rs As Recordset
Private Sub Form_Open(Cancel As Integer)
Text468.Text = frmLogin!strId
End Sub
【问题讨论】:
-
密码不属于数据库中的纯文本。 Hash+salt 密码,存储加盐的哈希。然后哈希+盐(相同的盐值)输入,并与存储的值进行比较。如果它们匹配,则密码很好。比较哈希,而不是纯文本密码。
-
我在字段上使用密码输入掩码。可以吗?
-
我说的是数据库中的内容。如果您以纯文本形式存储密码,则任何可以访问数据库表的人都可以伪造任何凭据,即可能没有任何密码,您不能 100% 确定记录的凭据是凭据的人宣称。输入掩码很棒,但解决了在您输入密码时有人从背后偷看您的安全问题 - 它不会使系统真正安全。
-
普通用户无法访问这些数据库,但如果这是我需要做的事情,我可能会在稍后添加。我会做一些研究。
-
专业提示:安全性是一项功能,而不是附加组件。您的“不正常”用户 /devs 可以很容易地访问任何人的凭据。根据此应用程序正在做什么以及需要保护它的原因,您不希望允许这样做。这就是每一次安全漏洞的发生方式:开发人员认为他们可以在以后保护事情。