SQL databases are commonly used to store data; for example - your application could store user profile information in a database. Yous should never create inline SQL or other database queries in your code using raw user input and send it directly to the database; this behavior is a recipe for disaster, as we saw above.

For example - do not create code like the following inline SQL example:

string userName = Request.QueryString["username"]; // receive input from the user BEWARE!
...
string query = "SELECT * FROM [dbo].[users] WHERE userName = '" + userName + "'";

Here we concatenate text strings together to create the query, taking the input from the user and generating a dynamic SQL query to look up the user. Again, if a malicious user realized we were doing this, or just tried different input styles to see if there was a vulnerability, we could end up with a major disaster. Instead, use parameterized SQL statements or stored procedures such as this:

-- Lookup a user
CREATE PROCEDURE sp_findUser
(
@UserName varchar(50)
) SELECT * FROM [dbo].[users] WHERE userName = @UserName

With this method you can invoke the procedure from your code safely, passing it the userName string without worrying about it being treated as part of the SQL statement.

最新文章

  1. nginx下搭建CodeIgniter问题集锦
  2. readonly
  3. struct内存对齐1:gcc与VC的差别
  4. ArcGIS Viewer for Flex中引入google map作底图
  5. Coding 初级教程(一)——用GitHub的GUI客户端对Coding的项目进行管理
  6. Android中ListView中有button,checkbox,GridView时事件问题
  7. BZOJ 1588 营业额统计 Splay
  8. 技术贴 本地代码与svn关联教程 svn upgrade问题解决
  9. Kia's Calculation(贪心)
  10. 负载均衡集群之LVS持久链接
  11. CPU自制入门——笔记
  12. 动手Jquery插件
  13. tabBarItem动画
  14. js中的写出想jquery中的函数一样调用
  15. Winform DevExpress控件库(三) 使用NavBarControl控件定制导航栏
  16. noi.ac#309 Mas的童年(子集乱搞)
  17. MT2017笔试题
  18. LeetCode(116):填充同一层的兄弟节点
  19. 10.25 AITalkUat部署
  20. WebAssembly 浏览器中运行c/c++模块

热门文章

  1. Linux内核--伙伴系统--页释放
  2. 长乐国庆集训Day1
  3. day03——整型、字符串、for循环
  4. centos7中mysql的rpm包安装
  5. 【LEETCODE】61、对leetcode的想法&数组分类,适中级别,题目:162、73
  6. golang 之 flag
  7. java基础 String
  8. Linux 软链接和硬链接简介
  9. Java多线程并发同步执行
  10. log4j使用指北