Click here to Skip to main content
15,923,376 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Password in Cookies Pin
Sandeep Akhare10-Sep-07 20:28
Sandeep Akhare10-Sep-07 20:28 
GeneralRe: Password in Cookies Pin
varshavmane10-Sep-07 22:44
varshavmane10-Sep-07 22:44 
GeneralRe: Password in Cookies Pin
Sandeep Akhare10-Sep-07 23:37
Sandeep Akhare10-Sep-07 23:37 
GeneralRe: Password in Cookies Pin
varshavmane11-Sep-07 0:06
varshavmane11-Sep-07 0:06 
GeneralRe: Password in Cookies Pin
Sandeep Akhare11-Sep-07 0:37
Sandeep Akhare11-Sep-07 0:37 
GeneralRe: Password in Cookies Pin
varshavmane11-Sep-07 0:53
varshavmane11-Sep-07 0:53 
GeneralRe: Password in Cookies Pin
Sandeep Akhare11-Sep-07 1:02
Sandeep Akhare11-Sep-07 1:02 
GeneralRe: Password in Cookies Pin
varshavmane11-Sep-07 1:20
varshavmane11-Sep-07 1:20 
I am implementing Logout ie When I logout all the cookies must be removed and when I login with new user name cookies should be replace with that. Here is the code:
Login.asp.cs
protected void Page_Load(object sender, EventArgs e)
{
Session["CompanyName"] = "FLAG";
txtPassword.Attributes.Add("OnFocus", "javascript:readCookie();");
}

protected void ibtnLogin_Click(object sender, ImageClickEventArgs e)
{
clsFunctions cs = new clsFunctions();
DataSet ds = new DataSet();
String str = "Select LoginId,LoginName ,Password from tbUser where LoginName= '" + txtId.Value + "' and Password ='" + txtPassword.Value + "' and UserGroupId= 1";
ds=cs.Return_Dataset(str,cs.connectionDBcentral() );
lblMessage.Visible = false;
if (ds.Tables[0].Rows.Count > 0)
{
HttpContext.Current.Cache.Insert(txtId.Value, ds.Tables[0].Rows[0][0]);

if (chkRememberMe.Checked)
{
HttpCookie RememberMe = new HttpCookie("RememberMe");

RememberMe.Values.Add("", txtId.Value + "|" + txtPassword.Value + ";");
RememberMe.Expires.AddMinutes(2);
Response.Cookies.Add(RememberMe);

Session.Add("Check", "On");
Session.Add("Country", "0");
Session.Add("logname", txtId.Value);
Session.Add("loginId", ds.Tables[0].Rows[0][0]);
Response.Redirect("Home.aspx");
}
else
{
HttpContext.Current.Cache.Insert(txtId.Value, ds.Tables[0].Rows[0][0]);
Session.Add("Check", "On");
Session.Add("Country", "0");
Session.Add("logname", txtId.Value);
Session.Add("loginId", ds.Tables[0].Rows[0][0]);
Response.Redirect("Home.aspx");
}
}
else
{
Session.Add("Check", "Off");
lblMessage.Text = "Invalid LoginName and Password";
lblMessage.Visible = true;
}
}

JavaScript function:

function readCookie()
{
var txtuname= document.getElementById('txtId');
var txtpass= document.getElementById('txtPassword');
if (document.cookie.length>0)
{
var c_start=document.cookie.indexOf(txtuname.value);

if (c_start!=-1)
{
c_start=c_start + txtuname.value.length +1 ;
var c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1)
{
c_end=document.cookie.length;
}
var value= unescape(document.cookie.substring(c_start,c_end));
var arr = new Array(2);
arr= value.split('|',2)
alert(arr[0]);
// alert("Username "+arr[0]);
// alert("Password "+arr[1]);
txtuname.value=arr[0];
txtpass.value=arr[1];
}
else
{
txtpass.value="";
}
}
}


Logout.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Cache.Remove(Session["logname"].ToString());
Session["Check"] = "off";
//Cache.Remove("RememberMe");
//HttpCookie RememberMe = new HttpCookie("RememberMe");
//RememberMe.Expires = DateTime.Now;

Response.Cookies["RememberMe"].Expires=DateTime.Now;

Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect("Login.aspx?action=SessionExpired", true);
}

I am not getting how to do.

Thanks again.

GeneralRe: Password in Cookies [modified] Pin
Sandeep Akhare11-Sep-07 1:11
Sandeep Akhare11-Sep-07 1:11 
GeneralRe: Password in Cookies Pin
varshavmane11-Sep-07 2:20
varshavmane11-Sep-07 2:20 
GeneralRe: Password in Cookies Pin
Sandeep Akhare11-Sep-07 3:25
Sandeep Akhare11-Sep-07 3:25 
QuestionI want to change the number format to Local Culture in JS by reading culture value from Web Config Pin
Arun Kumar Babu10-Sep-07 19:07
Arun Kumar Babu10-Sep-07 19:07 
QuestionForm authentication Pin
bhattiprolu10-Sep-07 19:01
bhattiprolu10-Sep-07 19:01 
AnswerRe: Form authentication Pin
varshavmane10-Sep-07 19:18
varshavmane10-Sep-07 19:18 
QuestionProblems in master page! Pin
Affan Toor10-Sep-07 19:00
Affan Toor10-Sep-07 19:00 
AnswerRe: Problems in master page! Pin
Sandeep Akhare10-Sep-07 19:30
Sandeep Akhare10-Sep-07 19:30 
QuestionPopup Window in FireFox Pin
Mahesh.J10-Sep-07 18:07
Mahesh.J10-Sep-07 18:07 
AnswerRe: Popup Window in FireFox Pin
Sandeep Akhare10-Sep-07 19:44
Sandeep Akhare10-Sep-07 19:44 
QuestionExprot to Word Is Error Pin
AnhTin10-Sep-07 17:06
AnhTin10-Sep-07 17:06 
QuestionDataset in ap.net2.0 Pin
dhulipudi10-Sep-07 16:28
dhulipudi10-Sep-07 16:28 
AnswerRe: Dataset in ap.net2.0 Pin
Sandeep Akhare10-Sep-07 19:48
Sandeep Akhare10-Sep-07 19:48 
GeneralRe: Dataset in ap.net2.0 Pin
dhulipudi10-Sep-07 19:52
dhulipudi10-Sep-07 19:52 
AnswerRe: Dataset in ap.net2.0 Pin
varshavmane10-Sep-07 20:19
varshavmane10-Sep-07 20:19 
GeneralRe: Dataset in ap.net2.0 Pin
dhulipudi10-Sep-07 20:37
dhulipudi10-Sep-07 20:37 
QuestionHow to improve the efficiency when search data from more than 1000000 records? Pin
guiqul16310-Sep-07 15:30
guiqul16310-Sep-07 15:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.