Solved

Getting and Setting Cookies

Posted on 2012-03-29
2
280 Views
Last Modified: 2012-03-29
Can anyone provide two scripts for getting and setting cookies.  The cookie name is "synkfba" and it will contain username and password.

If need to check to see if the cookie exists and if not create it.

Thanks.
0
Comment
Question by:sherbug1015
2 Comments
 
LVL 4

Accepted Solution

by:
elliottbenzle earned 500 total points
ID: 37782876
I think you will need to set separate cookies for user and password:

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub SubmitBtnWrite_Click(Sender As Object, E As EventArgs)
        Response.Cookies("synkfba").Expires = "5/1/2013"
        Response.Cookies("synkfba").Value = _
            "User_name"
        Response.Cookies("synkfba-password").Expires = "5/1/2013"
        Response.Cookies("synkfba-password").Value = _
            "User_password."
End Sub
Sub SubmitBtnRead_Click(Sender As Object, E As EventArgs)
    Dim I as integer
    For I = 0 to Request.Cookies.Count - 1
        lblMessage1.Text = lblMessage1.Text  _
            & Request.Cookies.Item(I).Name & ": " _
            & Request.Cookies.Item(I).Value & "<BR>"
    Next
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Cookies Sample Page</TITLE>
</HEAD>
<BODY >
<form runat="server">
<Font Face="Tahoma">
<asp:Label
    id="lblMessage1"
    runat="Server"
    Font-Bold="True"
/>
<BR><BR>
<asp:button
    id="butOK1"
    runat="server"
    text="Write Cookies to Browser"
    Type="Submit"
    OnClick="SubmitBtnWrite_Click"
/>
<asp:button
    id="butOK2"
    runat="server"
    text="Read Cookies from Browser"
    Type="Submit"
    OnClick="SubmitBtnRead_Click"
/>
</Font>
</Form>
</BODY>
</HTML>
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37783507
It is considered very insecure and bad practice to store usernames and passwords in cookies because that makes them available to anyone who uses that computer.  Cookies stored on the computer are just text files that can be easily read.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question