zoukankan      html  css  js  c++  java
  • sql 登录注入

    DataTable dt= SqlHelper.ExecuteDataTable(System.Data.CommandType.Text, String.Format("select * from Automation_User where userName='{0}' and password='{1}'", userName, password), null);

    如果是拼接式sql登录的话很容易进行sql注入

    'or'1'='1

    所以登录的sql尽量写成参数化,

    using (SqlConnection cnn = new SqlConnection(con))
    {
    using (SqlCommand cmd = cnn.CreateCommand())
    {
    try
    {
    cmd.CommandText = "select * from User where username=@username and password=@password";
    cmd.Parameters.Add(new SqlParameter("@username", username));
    cmd.Parameters.Add(new SqlParameter("@password", password));
    SqlDataAdapter da = new SqlDataAdapter();
    DataSet ds = new DataSet();
    da.SelectCommand = cmd;
    da.Fill(ds);
    cnn.Close(); //记得要加上 关闭
    if (ds.Tables[0].Rows.Count > 0)
    {
    type = Convert.ToInt32(ds.Tables[0].Rows[0]["type"]);
    }
    }
    catch (Exception ex)
    {
    // type = -2;
    logInstance.Info(string.Format("登录出现异常,异常信息为:{0}",ex.Message));
    }
    }
    }

    //参数化时,单引号和双引号都会被转义

  • 相关阅读:
    iOS优化内存方法推荐
    Swift和OC,是编译型语言、解释性语言、运行时语言
    redis常用命令
    redis 基本类型
    spring中事务配置
    redis 基本概览
    ThreadLocal 类说明
    spring 中 AOP 功能
    ps抠图简单方法
    nginx配置文件中location说明
  • 原文地址:https://www.cnblogs.com/yangjinwang/p/4647948.html
Copyright © 2011-2022 走看看