Click here to Skip to main content
15,887,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all!
I want to store user name and password for the next time if user check remember me for next time in 'Login control' in web application.
Master page is used here. So i want to check that is user valid or not so that user can authorized for the rights.
Posted
Comments
Sandeep Mewara 30-Apr-11 12:35pm    
Tried anything?

This is common feature websites offer and most will use client side cookies stored as a maker that the user was logged on on that machine. Have a look at w3schools:
http://www.w3schools.com/JS/js_cookies.asp[^]
for how to set/retrieve cookies through javascript which you can then use to log a user in through AJAX:
AJAX Tutorial[^]

You should, however, make sure that any AJX calls you make to your server are encrypted or over a secure connection as otherwise someone can simply intercept the calls to get a user's password. Also look at the folllwing snippet that shows how to add client cookies from server side responses:

http://www.dotnetspider.com/resources/6599-Generate-Cookie-for-Remember-me-At-Login-time.aspx[^]
 
Share this answer
 
try this link

Click[^]
 
Share this answer
 
ASP.NET
.................
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cookie.aspx.cs" Inherits="Cookie" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        Username:<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox><br />
        Password:
        <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
        <br />
        <asp:CheckBox ID="chkremem" Text="Remember me next time?" runat="server" />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Login" OnClick="Button1_Click" />
    </div>
    </form>
</body>
</html>


...............
C#.NET
.........
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Cookie : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            HttpCookie un = Request.Cookies["Username"];
            HttpCookie pw = Request.Cookies["Password"];
            if (un.Value != "" && pw.Value != "")
            {
                string usname = un.Value;
                string passw = pw.Value;
                txtUsername.Text = usname;
                txtPassword.Text = passw;
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (chkremem.Checked == true)
        {


            HttpCookie myCookie = new HttpCookie("Username");
            HttpCookie myCookies = new HttpCookie("Password");
            myCookie.Value = txtUsername.Text;
            myCookies.Value = txtPassword.Text;
            myCookie.Expires = DateTime.Now.AddDays(1d);
            Response.Cookies.Add(myCookie);
            Response.Cookies.Add(myCookies);
            Response.Cookies["Username"].Expires = DateTime.Now.AddDays(1);
            Response.Cookies["Password"].Expires = DateTime.Now.AddDays(1);
        }
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900