zoukankan      html  css  js  c++  java
  • 登陆模块防止恶意用户SQL注入攻击 dodo

    可以采用通过存储过程参数的方法防止恶意用户使用“‘”攻击。
    函数:
    public SqlDataReader GetUserLoginByProc(string sUserName, string sPassword)
    {
        //创建连接
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
        //创建Command
       SqlCommand myCommand = new SqlCommand("Pr_GetUserLogin",myConnection);
        //设置为执行存储过程
       myCommand.CommandType = CommandType.StoredProcedure;
        //添加存储过程的参数
       SqlParameter pUserName = new SqlParameter("@UserName",SqlDbType.VarChar,32);
       pUserName.Value = sUserName;
        myCommand.Parameters.Add(pUserName);
        SqlParameter pPassword = new SqlParameter("@Password",SqlDbType.Varchar,255);
        pPassword.Value = sPassword;
        myCommand.Parameters.Add(pPassword);
        //定义DataReader
        SqlDataReader dr = null;
        try
        {
            //打开连接
           myConnection.Open();
           //读取数据
           myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch(SqlException ex)
        {
            //抛出异常
            throw new Exception(ex.Message,ex);
        }
        //返回DataReader
        return dr;
    }
    说明:代码是2.0下的。
  • 相关阅读:
    文件系统管理
    软件包管理
    用户和用户组管理
    权限管理
    漏洞验证系列--MongoDB未授权访问
    【Jenkins】三、设置定时任务
    在CentOS Linux 7.5上安装MySQL
    CentOS7使用yum时File contains no section headers.解决办法
    Windows批处理(cmd/bat)常用命令学习
    Fiddler抓包工具总结
  • 原文地址:https://www.cnblogs.com/zgqys1980/p/540658.html
Copyright © 2011-2022 走看看