博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
021-异步注册登录(检测用户名)
阅读量:4703 次
发布时间:2019-06-10

本文共 4553 字,大约阅读时间需要 15 分钟。

Register.html

1  2  3  4     
5 6 7 68 69 70
71 用户名:
72
73
74 密码:
75
76 重复密码:
77
78
79
80
81 82

Register.ashx

1     public class Register : IHttpHandler 2     { 3  4         public void ProcessRequest(HttpContext context) 5         { 6             context.Response.ContentType = "text/plain"; 7  8             //操作类型:1判断用户名是否存在,2进行注册insert 9             string action = context.Request["action"];10             if (action.Equals("1"))11             {12                 string sql = "select count(*) from userinfo where username=@name";13                 SqlParameter p = new SqlParameter("@name", context.Request["uname"]);14 15                 int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, p));16                 context.Response.Write(obj);17 18             }19             else if (action.Equals("2")) //注册20             {21                 string sql = "insert into userinfo values(@name,@pwd)";22                 SqlParameter[] ps =23                 {24                     new SqlParameter("@name",context.Request["uname"]),25                     new SqlParameter("@pwd",context.Request["upwd"])26                 };27 28                 int result = SqlHelper.ExecuteNonQuery(sql, ps);29                 context.Response.Write(result);30             }31 32 33         }34 35         public bool IsReusable36         {37             get38             {39                 return false;40             }41         }42     }

Login.html

1  2  3  4     
5 6 7 26 27 28
29 用户名:
30
31 密码:
32
33
34
35
36 37

Login.ashx

1     public class Login : IHttpHandler 2     { 3  4         public void ProcessRequest(HttpContext context) 5         { 6             context.Response.ContentType = "text/plain"; 7             int result = 1;//1成功,2用户名错,3密码错 8  9             string uname = context.Request["uname"];10             string upwd = context.Request["upwd"];11 12             string sql = "select userpwd from userinfo where username=@name";13             SqlParameter p = new SqlParameter("@name", uname);14 15             object upwd2 = SqlHelper.ExecuteScalar(sql, p);16             if (upwd2 == null)17             {18                 result = 2;19             }20             else if (upwd2.ToString().Equals(upwd))21             {22                 result = 1;23             }24             else25             {26                 result = 3;27             }28 29             context.Response.Write(result);30         }31 32         public bool IsReusable33         {34             get35             {36                 return false;37             }38         }39     }

SqlHelper.cs

1     public static class SqlHelper 2     { 3         private static string connStr = 4             System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString; 5  6         public static DataTable GetList(string sql, params SqlParameter[] ps) 7         { 8             using (SqlConnection conn = new SqlConnection(connStr)) 9             {10                 SqlDataAdapter sda = new SqlDataAdapter(sql, conn);11                 sda.SelectCommand.Parameters.AddRange(ps);12 13                 DataTable dt = new DataTable();14                 sda.Fill(dt);15 16                 return dt;17             }18         }19 20         public static int ExecuteNonQuery(string sql, params SqlParameter[] ps)21         {22             using (SqlConnection conn = new SqlConnection(connStr))23             {24                 SqlCommand cmd = new SqlCommand(sql, conn);25                 cmd.Parameters.AddRange(ps);26 27                 conn.Open();28                 return cmd.ExecuteNonQuery();29             }30         }31 32         public static object ExecuteScalar(string sql, params SqlParameter[] ps)33         {34             using (SqlConnection conn = new SqlConnection(connStr))35             {36                 SqlCommand cmd = new SqlCommand(sql, conn);37                 cmd.Parameters.AddRange(ps);38 39                 conn.Open();40                 return cmd.ExecuteScalar();41             }42         }43 44     }

Web.config

1 
2 3
7 8
9
10
11
12
13
14
15
16

 

转载于:https://www.cnblogs.com/ninghongkun/p/6345707.html

你可能感兴趣的文章
最新版IntelliJ IDEA2019 破解教程(2019.08.07-情人节更新)
查看>>
C# 两个datatable中的数据快速比较返回交集或差集
查看>>
关于oracle样例数据库emp、dept、salgrade的mysql脚本复杂查询分析
查看>>
adb shell am 的用法
查看>>
iOS10 UI教程视图和子视图的可见性
查看>>
FindChildControl与FindComponent
查看>>
中国城市json
查看>>
android下载手动下载Android SDK
查看>>
C++学习:任意合法状态下汉诺塔的移动(原创)
查看>>
leetcode133 - Clone Graph - medium
查看>>
一点小基础
查看>>
UNET学习笔记2 - 高级API(HLAPI)
查看>>
"ORA-00942: 表或视图不存在 "的原因和解决方法[转]
查看>>
Oauth支持的5类 grant_type 及说明
查看>>
C#中用DateTime的ParseExact方法解析日期时间(excel中使用系统默认的日期格式)
查看>>
W3100SM-S 短信猫代码发送 上
查看>>
Linux IO模式及 select、poll、epoll详解
查看>>
Log4j知识汇总
查看>>
C# winform 使用DsoFramer 创建 显示office 文档
查看>>
找工作的一些感悟——前端小菜的成长
查看>>