【发布时间】:2012-04-11 00:51:39
【问题描述】:
谁能为 Asp.NET 1.1 推荐这样的库?
谢谢。
【问题讨论】:
-
有一个更快的解决方案,您可以查看:forums.asp.net/t/1254125.aspx
标签: sql-injection
谁能为 Asp.NET 1.1 推荐这样的库?
谢谢。
【问题讨论】:
标签: sql-injection
有很多选择,但老实说,最好的工具是教育。知道如何自己预防。如果使用得当,内置在普通框架类库中的工具是完全足够的。
对每个数据库调用简单地使用参数化查询和/或存储过程是最好的预防措施。
不过,话虽如此,我们确实使用 Microsoft 模式和实践库提供的 Microsoft.Practices.EnterpriseLibrary.Data 类。我们使用的那些有点过时,但仍然可以很好地完成工作。它们提供了一些注入保护并简化了数据访问。但它们不是完成这项工作的唯一工具,也不一定是最好的工具。
有关当前模式和实践库的更多最新信息,请访问here。
【讨论】:
<?PHP
FUNCTION anti_injection( $user, $pass ) {
// We'll first get rid of any special characters using a simple regex statement.
// After that, we'll get rid of any SQL command words using a string replacment.
$banlist = ARRAY (
"insert", "select", "update", "delete", "distinct", "having", "truncate", "replace",
"handler", "like", " as ", "or ", "procedure", "limit", "order by", "group by", "asc", "desc"
);
// ---------------------------------------------
IF ( EREGI ( "[a-zA-Z0-9]+", $user ) ) {
$user = TRIM ( STR_REPLACE ( $banlist, '', STRTOLOWER ( $user ) ) );
} ELSE {
$user = NULL;
}
// ---------------------------------------------
// Now to make sure the given password is an alphanumerical string
// devoid of any special characters. strtolower() is being used
// because unfortunately, str_ireplace() only works with PHP5.
IF ( EREGI ( "[a-zA-Z0-9]+", $pass ) ) {
$pass = TRIM ( STR_REPLACE ( $banlist, '', STRTOLOWER ( $pass ) ) );
} ELSE {
$pass = NULL;
}
// ---------------------------------------------
// Now to make an array so we can dump these variables into the SQL query.
// If either user or pass is NULL (because of inclusion of illegal characters),
// the whole script will stop dead in its tracks.
$array = ARRAY ( 'user' => $user, 'pass' => $pass );
// ---------------------------------------------
IF ( IN_ARRAY ( NULL, $array ) ) {
DIE ( 'Invalid use of login and/or password. Please use a normal method.' );
} ELSE {
RETURN $array;
}
}
[1]: http://psoug.org/snippet/PHP-Anti-SQL-Injection-Function_18.htm
[1]: http://psoug.org/snippet/PHP-Anti-SQL-Injection-Function_18.htm
【讨论】: