ASP.NET 登录源代码

今天上ASP.NET课的任务是完成一个登录界面。 下面我把源代码分享给大家。 登录界面效果展示 [code lang="java"] using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Collections; public partial class _UserLogin : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.Image1.ImageUrl = "ValidateCode.aspx"; //验证码网页 } } //单击登陆先判断验证码正确后判断用户名和密码; protected void Button1_Click(object sender, EventArgs e) //点击 登录按钮 { //创建连接 SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=sa;"); //SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connString"]); if (Session["CheckCode"].ToString().Equals(TextBoxYzm.Text.ToString().ToUpper())) { try { con.Open(); SqlCommand com = new SqlCommand("select @count=count(*) from loginInfo where name=@name and pwd=@ps", con);//在数据表loginInfo中查找用户名和密码 用参数的方式更具有安全性 com.Parameters.Add(new SqlParameter("@name", SqlDbType.VarChar, 50)); com.Parameters["@name"].Value = TextName.Text; com.Parameters.Add(new SqlParameter("@count", SqlDbType.Int, 4)); com.Parameters["@count"].Direction = ParameterDirection.Output; com.Parameters.Add(new SqlParameter("@ps",SqlDbType.VarChar, 50)); com.Parameters["@ps"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(TextPass.Text, "MD5");//给密码字段加密 com.ExecuteNonQuery(); int i = int.Parse( com.Parameters["@count"].Value.ToString()); if (i > 0) { //添加登陆日志 com = new SqlCommand("insert LoginLog values('" + TextName.Text + "','" + DateTime.Now.ToString() + "')", con); com.ExecuteNonQuery(); con.Close(); FormsAuthentication.RedirectFromLoginPage(TextName.Text, true);//写入身份认证cookie } else { Response.Write("<script>alert('密码或用户名错误!')</script>"); } } catch (Exception error) { Response.Write(error.ToString()); } } else Response.Write("<script>alert('验证码错误!')</script>"); } protected void LinkButton2_Click(object sender, EventArgs e) //点击 看不清 按钮 { this.Image1.ImageUrl = "ValidateCode.aspx"; //刷新验证码 } } [/code] 要运行以上代码需要数据库的 数据库 数据库表
posted on 2012-04-19 18:24 刘浒 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/liuhu/archive/2012/04/19/3322379.html

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值