登录时记住我的密码 [英] Remember My Password At The Time Of Login

查看:61
本文介绍了登录时记住我的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net登录时记住我的密码,请使用asp.net中的复选框给我代码来记住密码

解决方案

< blockquote>看看这个代码项目的帖子记住我下次登录asp.net中的登录控制 [ ^ ]



请记住 - 记住密码否定了拥有密码的原因一个在第一位


在表单上放置一个CheckBox来控制用户是否想要记住密码。如果选中此选项,请将用户名和密码存储在cookie中。这是当用户稍后返回您的应用程序时将检查的cookie。对于奖励积分,请在Cookie中设置过期日期,以便在用户未返回您的网站一段时间后再次登录 - 1个月似乎是合理的价值。


在这里你去,



第一步: -

在aspx中添加这些



 <   tr  >  
< td width = 12% align = right > < 输入 id = chkbxRempasss type = 复选框 runat = server name = 复选框 value = 复选框 / > < / td >
< td width = 88% > < span class = table-col2_7 > 请记住我的密码< / span > < / td >
< / tr >





第二步: -

在Aspx.cs中你可以写这样的东西来存储它cookies



  public  部分  class 登录:System.Web.UI.Page 
{
string username = string .Empty;
string pwd = string .Empty;
string encytpwd = string .Empty;
string UserID = string .Empty;
ProcessService ProcessService = new ProcessService();

受保护 void Page_Load(对象 sender,EventArgs e)
{
if (Request.Cookies [ myCookie]!= null
{
HttpCookie cookie = Request.Cookies.Get( myCookie);
// txtUserName.Value = cookie.Values [username];
txtUserName.Attributes.Add( value,cookie.Values [ username]);
// txtPwd.Value = cookie.Values [password];
txtPwd.Attributes.Add( value,cookie.Values [ password]);

Response.Cookies [ myCookie]。Expires = DateTime.Now .AddDays(-1);
// Response.Cookies [Txt_Password.Text] .Expires = DateTime.Now.AddDays(-1) ;
chkbxRempasss.Checked = true ;
}

if (Page.Request.Params.Get( __ EVENTTARGET)!= null
{
ChkUserLogin();
}
}
// 检查登录凭据
protected void ChkUserLogin()
{
尝试
{
HttpCookie myCookie = new HttpCookie( myCookie);
if (chkbxRempasss.Checked == true
{
myCookie.Values.Add( username,txtUserName.Text.ToString());
myCookie.Values.Add( password,txtPwd.Text.ToString()) ;
myCookie.Expires = DateTime.Now.AddDays( 15 );
Response.Cookies.Add(myCookie);
}

username = txtUserName.Text.ToString();
pwd = txtPwd.Text.ToString();
encytpwd =加密(pwd, &%#@?,:*) ;
string result = string .Empty;
result = ProcessService.ChkUserLogin(username,encytpwd);
if (result == 0
{
DataSet User = ProcessService.getLoginuserdetails(username);
UserID = User.Tables [ 0 ]。行[ 0 ] [ 0 ]的ToString();
会话[ UserID] = UserID.ToString();
Response.Redirect( Default.aspx);
}
else if (result == 1
{
lblAlert.Text = 无效的用户名。;
lblAlert.ForeColor = System.Drawing.Color.Red;
lblAlert.Visible = true ;
}
else if (result == 2
{
lblAlert.Text = 密码无效。;
lblAlert.ForeColor = System.Drawing.Color.Red;
lblAlert.Visible = true ;
}
}
catch (Exception exn)
{
}
最后
{
}
}





所有最好:)如果你需要进一步的支持,请回信!


Remember My Password At The Time Of Login in asp.net,please give me the code to remember the password by using check in the checkbox in asp.net

解决方案

Have a look at this codeproject post Remember me next time in login control in asp.net[^]

Bear in mind - remembering a password negates the reason for having one in the first place


Put a CheckBox on your form to control whether or not the user wants to remember the password. If this is checked, store the username and password in a cookie. This is the cookie that you will be checking when the user comes back to your application later on. For bonus points, put an expiration date in the cookie so that the user will be required to log in again if they don't come back to your site for some period of time - 1 month seems a reasonable value.


Here you go ,

Step1:-
In aspx add these

<tr>
                        <td width="12%" align="right"><input id="chkbxRempasss" type="checkbox" runat="server" name="checkbox" value="checkbox" /></td>
                        <td width="88%"><span class="table-col2_7">Remember my password </span></td>
                      </tr>



Step2:-
In Aspx.cs you can write something like this to store it in cookies

public partial class Login : System.Web.UI.Page
    {
        string username = string.Empty;
        string pwd = string.Empty;
        string encytpwd = string.Empty;
        string UserID = string.Empty;
        ProcessService ProcessService = new ProcessService();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["myCookie"] != null)       
            {            
                HttpCookie cookie = Request.Cookies.Get("myCookie");            
                //txtUserName.Value = cookie.Values["username"];            
                txtUserName.Attributes.Add("value", cookie.Values["username"]);
                //txtPwd.Value = cookie.Values["password"];            
                txtPwd.Attributes.Add("value", cookie.Values["password"]);

                Response.Cookies["myCookie"].Expires = DateTime.Now.AddDays(-1);            
                //Response.Cookies[Txt_Password.Text].Expires = DateTime.Now.AddDays(-1);
                chkbxRempasss.Checked = true;
            }

            if (Page.Request.Params.Get("__EVENTTARGET") != null)
            {
                ChkUserLogin();
            }
        }
//Check Login Credentials
        protected void ChkUserLogin()
        {
            try
            {
                HttpCookie myCookie = new HttpCookie("myCookie"); 
                if (chkbxRempasss.Checked == true) 
                { 
                    myCookie.Values.Add("username", txtUserName.Text.ToString()); 
                    myCookie.Values.Add("password", txtPwd.Text.ToString()); 
                    myCookie.Expires = DateTime.Now.AddDays(15); 
                    Response.Cookies.Add(myCookie); 
                }

                username = txtUserName.Text.ToString();
                pwd = txtPwd.Text.ToString();
                encytpwd = Encrypt(pwd, "&%#@?,:*");
                string result = string.Empty;
                result = ProcessService.ChkUserLogin(username, encytpwd);
                if (result == "0")
                {
                    DataSet User = ProcessService.getLoginuserdetails(username);
                    UserID = User.Tables[0].Rows[0][0].ToString();
                    Session["UserID"] = UserID.ToString();
                    Response.Redirect("Default.aspx");
                }
                else if (result == "1")
                {
                    lblAlert.Text = "Invalid UserName.";
                    lblAlert.ForeColor = System.Drawing.Color.Red;
                    lblAlert.Visible = true;
                }
                else if (result == "2")
                {
                    lblAlert.Text = "Invalid Password.";
                    lblAlert.ForeColor = System.Drawing.Color.Red;
                    lblAlert.Visible = true;
                }
            }
            catch (Exception exn)
            {
            }
            finally
            {
            }
        }



All the best:) write back if you need further support!


这篇关于登录时记住我的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆