表单验证与按键问题
Form validation with Key Press Issues
昨晚,我接到主管的电话,说当他试图用虚拟密码登录我们的应用程序时,他的验证成功了。
事实证明,单击鼠标验证密码工作正常,因为使用无效密码的用户被拒绝访问。
但是,输入密码并按下键盘上的ENTER
键将允许用户访问系统。
有人知道为什么会发生这种情况以及如何防止它继续发生吗?
Protected Sub btn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn.Click
Dim StrPass As String
Dim BValid As Boolean
Dim rs As SqlDataReader
Dim StrSQL As String
'Protect against SQL Injection
StrPass = Replace(txtPass.Text, "'", "''", 1, -1, 1)
' This is our boolean variable for validation purposes set to true if valid user
BValid = False
StrSQL = "select * from users u " & _
" Where u.pass =@pass"
' Initialize Database Connection
Dim connStr As String = ConfigurationManager.ConnectionStrings("dbconn").ConnectionString
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand(StrSQL, conn)
'We use parametized query to prevent sql injection attack
Dim p1 As New SqlParameter("@pass", StrPass)
cmd.Parameters.Add(p1)
'Now open connection to the db
conn.Open()
'open recordset to receive db values
rs = cmd.ExecuteReader()
While rs.Read()
If rs("pass") <> "" Then
Session("pass") = txtPass.Text
BValid = True
Else
End If
End While
' No leaking allowed
conn.Close()
' This handles all response per validation
If BValid = True Then
dbto.Hide()
Else
'If all else fails, then reject their athentication attempt and let them hear it.
lblWrong.Text = "Incorrect pass entered."
End If
End Sub
的标记
<tr>
<td>
<asp:Label runat="server" ID="lblPass" Text="Please enter Password: " Font-Size="14pt"/>
<asp:TextBox runat="server" ID="txtPass" TextMode="Password" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btn" runat="server" Text="Submit" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblWrong" runat="server" ForeColor="Red" Font-Names="Tahoma" />
</td>
</tr>
把你的内容放在面板上,并分配默认按钮。
相关文章:
- javascript中添加验证电子邮件的问题
- Javascript验证问题
- CRM身份验证问题
- 获取json结果的身份验证问题
- 关于验证和语义标记的一些基本HTML5问题
- 为密码验证实现正则表达式时出现问题
- JS表单验证问题
- 在 mongodb 和 expressjs 中验证事物的问题
- 如何在窗体中使用多个按钮解决验证问题
- 带有jquery验证问题的php表单
- jQuery表单验证和提交问题
- Javascript if语句问题,以及如何在jquery中验证颜色
- jQuery表单验证插件's只有文字字段的问题
- 在Internet Explorer 11中使用SoundCloud进行身份验证时出现问题
- Jquery表单验证脚本问题
- Google UiApp中的Google Apps脚本验证问题
- 小数、逗号和客户端验证的问题
- 使用 jQuery 问题验证和提交表单
- 自定义jQuery的问题.验证器规则
- 使用jquery有问题.验证器和格式散列一起工作