How to implement cookies to save your ID and Password (ASP.NET)
"Cookies can be defined as a small text files that are created by Web Server and saved by Web Browser on Client's Machine"
However, if clients machine has disabled 'Cookies' , the script to create & store cookies will lose its effect.
Here, we are going to create a LOGIN page, that ask user to enter it's ID and PASSWORD. Also, if user selects, 'Keep me Signed in' for next visit, we'll save its ID & Password
Following are the name of controls on our LOGIN Page:
1. idlbl for Your Id Label
2. idtxt for textbox where User ID will be entered. Also set its AUTOPOSTBACK property to TRUE
3. passlbl for Password Label
4. Passtxt for textbox where password will be entered.
5. loginbtn for LOGIN button
Write following declaration statement in General Section
Dim uid as HttpCookie
Write following code at LOGIN Button
if checkbox1.chcked=true then
uid = New HttpCookie(idtxt.text)
uid.value=passtxt.text
Response.Cookie.Add(uid)
Response.Cookie(uid).Expires=DateTime.Now.AddDays(5)
end if
Write following statement at page_load event of LOGIN Page
uid=Request.Cookies.Get(idxt.text)
if Not uid Is Nothing Then
passtxt.text = uid.value
endif
That's all what we need to maintain cookies with our ASP.NET Page. For Further Queries and Suggestion, please Leave a comment.
Watch out for Next Tutorial Tomorrow.
Thanks & Have a great Programming Day, AartiAkhilesh Rathore
However, if clients machine has disabled 'Cookies' , the script to create & store cookies will lose its effect.
Here, we are going to create a LOGIN page, that ask user to enter it's ID and PASSWORD. Also, if user selects, 'Keep me Signed in' for next visit, we'll save its ID & Password
Following are the name of controls on our LOGIN Page:
1. idlbl for Your Id Label
2. idtxt for textbox where User ID will be entered. Also set its AUTOPOSTBACK property to TRUE
3. passlbl for Password Label
4. Passtxt for textbox where password will be entered.
5. loginbtn for LOGIN button
Write following declaration statement in General Section
Dim uid as HttpCookie
Write following code at LOGIN Button
if checkbox1.chcked=true then
uid = New HttpCookie(idtxt.text)
uid.value=passtxt.text
Response.Cookie.Add(uid)
Response.Cookie(uid).Expires=DateTime.Now.AddDays(5)
end if
Write following statement at page_load event of LOGIN Page
uid=Request.Cookies.Get(idxt.text)
if Not uid Is Nothing Then
passtxt.text = uid.value
endif
That's all what we need to maintain cookies with our ASP.NET Page. For Further Queries and Suggestion, please Leave a comment.
Watch out for Next Tutorial Tomorrow.
Thanks & Have a great Programming Day, AartiAkhilesh Rathore

Comments
Post a Comment