深圳全飞鸿

标题: VB加入简单的防SQL注入 [打印本页]

作者: syant    时间: 2019-5-4 11:56
标题: VB加入简单的防SQL注入
本帖最后由 syant 于 2019-5-4 12:41 编辑

VB加入简单的防SQL注入

  1. Private Sub TextInput_Keypress(KeyAscii As Integer)
  2. On Error GoTo TextInput_KeyPress_Error

  3. If Chr(KeyAscii) = "'" Then KeyAscii = 0
  4. If Chr(KeyAscii) = ";" Then KeyAscii = 0
  5. KeyAscii = TextFilter(KeyAscii, AlphaCap)
  6. If KeyAscii = 13 Then
  7.    ...
  8.    GoTo result
  9.    ...
  10.    result:
  11.       TextInput.SetFocus
  12.       TextInput.SelStart = 0
  13.       TextInput.SelLength = Len(TextInput.text)
  14. End If
  15. Exit Sub
  16. TextInput_KeyPress_Error:
  17.     MsgBox Err.Description, vbExclamation
  18. End Sub
复制代码

作者: syant    时间: 2019-5-4 12:31
  1. Public Function TextFilter(fAsc As Integer, fMode As Integer) As Integer
  2. On Error GoTo ErrorHandle

  3.     Select Case fMode
  4.         Case NumOnly  'Number Only
  5.             TextFilter = IIf(fAsc >= 48 And fAsc <= 57 Or fAsc = 8, fAsc, 0)
  6.         Case NumPoint  'Number & char '.'
  7.             TextFilter = IIf(fAsc >= 48 And fAsc <= 57 Or fAsc = 46 Or fAsc = 8, fAsc, 0)
  8.         Case NumTime  'Number & char ':'
  9.             TextFilter = IIf(fAsc >= 48 And fAsc <= 57 Or fAsc = 58 Or fAsc = 8, fAsc, 0)
  10.         Case AlphaCap  'Alpha Caption
  11.             If fAsc = 39 Then fAsc = 0
  12.             TextFilter = IIf(fAsc >= 97 And fAsc <= 122, fAsc - 32, fAsc)
  13.     End Select
  14.     Exit Function
  15. ErrorHandle:
  16.     MsgBox Err.Description, vbCritical

  17. End Function
复制代码





欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/) Powered by Discuz! X3.2