为了账号安全,请及时绑定邮箱和手机立即绑定

参考这个方法写一个 查询!

参考这个方法写一个 查询!

慕尼黑5688855 2018-12-07 03:20:31
   public static int ValidateUserInfo(string userName, string userPwd)        {            SqlDataReader tablePws = null;            string md5pws = ToMD5(userPwd);             SqlConnection conn = new SqlConnection();            conn.ConnectionString = staticValue.staticValue.userDB;            SqlCommand cmd = new SqlCommand();            cmd.Connection = conn;             cmd.CommandText = string.Format("select password,Id from u_users where (LoginName='{0}' or handphone='{2}' or eMail='{3}')", userName);            conn.Open();            tablePws = cmd.ExecuteReader();            cmd.Dispose();            conn.Close();            conn.Dispose();             if (tablePws == null)            {                return -1;            }            else            {                string key = Encoding.Unicode.GetString(tablePws["password"] as byte[]);                if (md5pws == Decrypt(key))                {                    int userId = 0;                    int.TryParse(tablePws["Id"].ToString(), out userId);                    return userId;                }                return -1;            }        } 姓名 ID 等等
查看完整描述

1 回答

?
慕森王

TA贡献1777条经验 获得超3个赞

cmd.CommandText = string.Format("select password,Id from u_users where (LoginName='{0}' or handphone='{2}' or eMail='{3}')", userName);

你没有写入{1} 就直接从0-》2了,应该有错的。

查看完整回答
反对 回复 2019-01-07
  • 1 回答
  • 0 关注
  • 518 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信