1. csdn的登陆,如果验证码填错,会弹出个alert,然后点了确定之后,除了账号还在,其他全部清空了。
这个账号还在的效果是怎么搞的?2. 记住用户名,下次打开该网站的时候不用输入用户名了。(同理,记住密码)3. 2周内不用登陆。以上3点,很想知道怎么做的,能力有限想不出来。希望高人指点一二,谢过
这个账号还在的效果是怎么搞的?2. 记住用户名,下次打开该网站的时候不用输入用户名了。(同理,记住密码)3. 2周内不用登陆。以上3点,很想知道怎么做的,能力有限想不出来。希望高人指点一二,谢过
解决方案 »
- 图片不显示
- .net 将一个字符串和一个数字连成一个字符串,作为变量名,并赋值
- .netFramewrok,asp.net的验证码如何生成?
- 我在一个asp的项目里加了一个功能,用.net实现的,现在无法在iis里浏览,请问这是为什么???
- DataGrid 中CheckBox 选中后的问题
- 热心人请进呀,datagrid问题,一上午都没人回贴了,郁闷
- 20分.一个很简单的问题.
- 在线求助
- Response.Redirect("url.aspx?id=1")在左框架,运行他后如何在右框架后打开url.aspx。
- 如何用让页面上的打印按钮不弹出打印对话框?并且用代码指定打印机...
- 请问高手为什么这个网站居然可以用支付宝登录?是怎么处理的?希望高手能说清楚
- 项目--谁来
正确不过还有,就是csdn也用了session,来看用户当前是否在线,
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
<div id="Div1" class="login">
<div class="lgnContent">
<div class="lgnList">用户名:
<asp:TextBox ID="UName" runat="server" CssClass="inputbtn" MaxLength="20" Width="120px"></asp:TextBox>
</div>
<div class="lgnList">密 码:
<asp:TextBox ID="UPsw" runat="server" TextMode="password" CssClass="inputbtn" MaxLength="20" Width="120px"></asp:TextBox>
</div>
<div class="lgnList">验证码:
<asp:TextBox ID="ValidCode" runat="server" CssClass="inputbtn" MaxLength="5" Width="40px"></asp:TextBox>
<a href="javascript:" onfocus="this.blur()" onclick="document.getElementById('<%=imgbtnCode.ClientID %>').src='<%=this.ResolveClientUrl("~/AdInterface/CheckCode.aspx") %>?date='+new Date();return false;">
<asp:ImageButton ID="imgbtnCode" AlternateText="验证码" ToolTip="看不清,换一张" runat="server" Enabled="false" ImageUrl="~/AdInterface/CheckCode.aspx" align="absmiddle" />
</a>
</div>
<div class="lgnList_btn">
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:Button runat="server" ID="BtnLogin" CssClass="lgnbtn" OnClick="BtnLogin_Click" />
<asp:Button runat="server" ID="BtnReset" CssClass="calbtn" />
<asp:Label runat="server" ID="result" ForeColor="red"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
const string STR_COOKIE_USERID="AdInterface_LoginID";
const string STR_COOKIE_USERPSW="AdInterface_LoginID";
protected void Page_Load(object sender, EventArgs e)
{
UName.Attributes.Add("onfocus", "document.getElementById('" + result.ClientID + "').innerText=''");
UPsw.Attributes.Add("onfocus", "document.getElementById('" + result.ClientID + "').innerText=''");
if (!IsPostBack)
{
if (Request.Cookies["AdInterface_LoginID"] != null) //调入保存帐号的cookie
{
this.UName.Text = Request.Cookies[STR_COOKIE_USERID].Value.ToString();
this.UPsw.Text = CommUtility.Descryp(Request.Cookies[STR_COOKIE_USERPSW].Value.ToString());
}
} }
protected void BtnLogin_Click(object sender, EventArgs e)
{
string id, psw;
id = CommUtility.Regular(this.UName.Text.Trim());
psw = CommUtility.Regular(this.UPsw.Text); if (Session["CHECKCODE"].ToString().ToLower() != ValidCode.Text.ToLower())
{
result.Text = "验证码错误!";
return ;
}
ServiceInterface service = new ServiceInterface();
if (service.CheckUserLogin(id, psw)) //合法
{
HttpCookie cookieID = new HttpCookie(STR_COOKIE_USERID);
HttpCookie cookiePsw = new HttpCookie(STR_COOKIE_USERPSW);
cookieID.Expires = DateTime.Now.AddDays(14);//帐号cookie保存时间为2周
cookiePsw.Expires = .Now.AddDays(14);
cookieID.Value = id;
cookiePsw.Value = CommUtility.EncrypDateTime(psw);
Response.Cookies.Add(cookieID);
Response.Cookies.Add(cookiePsw);
string scriptStr = "top.location.replace('OrderReports/AdMediaSharePage.aspx');";
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", scriptStr, true);
}
else
{
result.Text = "用户名或密码错误!";
return;
}
}
2,3:cookie
我们做个CSDN 的论坛的部分功能 发部分代码给你看下 希望对你有所帮助代码如下 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string name = this.TextBox1.Text.Trim().ToString();
string pass = this.TextBox2.Text.Trim().ToString();
if(name != "" && pass != "")
{ if (new UsersBll().ExistsLoginNames(name, pass))
{
string number = this.TextBox3.Text;
if (!Rnum.CheckSN(number)) //asp.net第三方控件 生成的验证码 此方法用于检查输出的是否和验证码一致
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "s", "alert('验证码错误')", true);//如果不一致弹出提示框
}
else
{
if (CheckBox1.Checked == true) 如果选中的话 则把它放入COOKIE中
{
HttpCookie cook = new HttpCookie("MyCook");
cook.Values["name"] = name;
cook.Expires = DateTime.Now.AddDays(14);
Response.Cookies.Add(cook);
}
Session["name"] = name;
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "s", "parent.window.location.href='Index.aspx'", true);
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "s", "alert('你提交的信息不正确')", true);
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "s", "alert('你的信息提交不完整,请核对后在提交')", true);
}
给你个思路吧:
1. 一般验证码都是保存在Sesseion中,在输入验证码的文件框失去焦点时,通过Ajax判断输入的验证码和Session中的验证码是否一致,根据AJAX返回信息进行判断.
2. 用户登陆后可以写一个Cookie来的保存用户信息,在页面Onload时读取Cookie中的用户信息,若不为空就赋给控件
3. 2周内不用登陆用的是Cookie保存用户信息.