asp.net如何实现简单的登陆功能

fromcuit 2012-05-16 10:07:51
如何实现简单的登陆功能, 登陆者的信息需要通过查询数据库里面有的才能登陆? 这个是如何实现的?

可否给个简单的列子
谢谢大家了
...全文
1075 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
patrickjiang 2013-03-18
  • 打赏
  • 举报
回复
http://www.51aspx.com/DownloadAuth/SessionLogin/3678
LemonSmile_ 2013-03-18
  • 打赏
  • 举报
回复
http://www.baidu.com/baidu?word=asp.net+%E7%99%BB%E5%BD%95%E7%A4%BA%E4%BE%8B&ie=utf-8
H_Gragon 2013-03-18
  • 打赏
  • 举报
回复
引用 3 楼 polo_longsan 的回复:
//后台代码 using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data;……
同意!
sjbcl2008 2013-03-18
  • 打赏
  • 举报
回复
呵呵,很简单,先建个项目,创建个页面,里面有用户名,密码 两个文本框,确认和重置。 在确认按钮事件下,和数据库进行交互,把用户名和密码和数据库中保存的用户和密码进行校对 如果密码加密了,那还经过加密和解密的过程 如果匹对正确,则返回一个值,然后就跳转到主页面 如果不正确,则返回一个值,给用户一个提示语。
fanxin_1999 2012-05-17
  • 打赏
  • 举报
回复
http://www.51aspx.com/

yp19910928 2012-05-17
  • 打赏
  • 举报
回复
http://www.51aspx.com/
polo_longsan 2012-05-16
  • 打赏
  • 举报
回复
//后台代码
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnOK_Click(object sender, EventArgs e)
{
string str = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; //连接数据库,在webconfig中配置
SqlConnection Conn = new SqlConnection(str);
Conn.Open();
string sql = "select * from Table_User where UserName=@UserName and PassWord=@PassWord" ;
SqlCommand Comm = new SqlCommand(sql, Conn);
Comm.Parameters.Add("UserName",TextBox1.Text);
Comm.Parameters.Add("PassWord",TextBox2.Text);
SqlDataReader sdr = Comm.ExecuteReader();
if (sdr.Read())
{
Session["UserName"] = TextBox1.Text;
Session["PassWord"] = TextBox2.Text;
Label1.Text = "登陆成功!";

}
else
{
Label1.Text = "无法登陆,用户名或密码错误!";
}
Conn.Close();
}

//protected void btnRS_Click(object sender, EventArgs e)
//{
// string str = "Data Source=WDENU4DSDQGMAF9;Initial Catalog=Login;Integrated Security=True";
// SqlConnection Conn = new SqlConnection(str);
// Conn.Open();
// string sql = "update Table_login set Pwd='" + TextBox3.Text + "'where UserName='" + TextBox1.Text + "' and Pwd='" + TextBox2.Text + "'";
// SqlCommand Comm = new SqlCommand(sql, Conn);
// int n = Comm.ExecuteNonQuery();
// if (n == 1)
// {
// Label1.Text = "密码修改成功!";
// }
// else
// {
// Label1.Text = "密码修改失败!";
// }
// Conn.Close();
//}



protected void btnRG1_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
}
//以下为配置文件
<?xml version="1.0"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ConnStr" connectionString="Data Source=WDENU4DSDQGMAF9;Initial Catalog=Login;Integrated Security=True"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>
moyanmoku 2012-05-16
  • 打赏
  • 举报
回复
呵呵。。。你能问出这个问题想你是个初学者!上来看到你的帖子,不妨详细的告诉你!
首先,你得建立一个aspx的页面列三个文本框,分别是:帐号、密码、验证码!还有就是两个按钮,即:登陆、重置。还有一个lable用来放随即数的!代码如下:
<div id="div" runat="server">
<asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox
<asp:Button ID="Button1" runat="server"onclick="ImageButton1_Click"/>
<br /><br />
      <asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label>     
<asp:TextBox ID="TextBox2" runat="server" BackColor="#EAEAEA" TextMode="Password" Width="155px"></asp:TextBox>   
<asp:ImageButton ID="ImageButton2" runat="server"
ImageUrl="~/Background images/button2.jpg" Width="52px" Height="19px"
onclick="ImageButton2_Click" />
<br /><br />
  
<asp:Label ID="Label3" runat="server" Text="验证码:"></asp:Label>    
<asp:TextBox ID="TextBox3" runat="server" BackColor="#EAEAEA" Width="155px"></asp:TextBox>    
<asp:Label ID="Label4" runat="server" ForeColor="white" Width="57px" Height="20px" Font-Names="幼圆" Font-Size="10pt" BackColor="#2B91D5"></asp:Label>
</div>
dalmeeme 2012-05-16
  • 打赏
  • 举报
回复
这里面有很多asp.net的实例,可下载:http://www.51aspx.com/

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧