ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 6th, 2004, 08:50 AM
aashton aashton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 30 aashton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Safely storing a password

Is there a safe way to store a password in a CFCOOKIE? I'd like to include a "Remember Me" feature in my login page, and the easiest way to do it is to set the username and password in a cookie. But when I do that the password is stored in plain text. Is there a better way?

Reply With Quote
  #2  
Old July 6th, 2004, 09:58 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
If the application is sensitive at all, do NOT store the password in a cookie. Cookies are plain text and very easy to view/intercept/modify. I would store the user's login status as a client variable and use that to determine whether to let them in or not on repeat visits. This way their password is not kept in the cookie, just the login status.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old July 6th, 2004, 10:32 AM
aashton aashton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 30 aashton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
That's what I figure, but I didn't know if there was a way to hash it and decrypt it.
Will a client variable still work after the session has expired though?

Reply With Quote
  #4  
Old July 6th, 2004, 10:38 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
Yes, client variables are not tied to session variables, though they are similar. You can sort of think of client variables as "across multiple session" variables. They're ususally stored in a database, though they are stored in the system registry by default (not a good idea, use a database). The only caveat of using client vars is that you can't store complex data types, only simple values like strings. That means so structures, arrays, querys, etc. Though given what you're trying to do this should not affect you.

You COULD encrypt the password in the cookie, but that probably wouldn't gain you anything because you'd also have to store the "seed" that you used in the hash along with the hashed password in the cookie, in order to decrypt it again. Which sort of makes the whole process useless (beyond simple obfuscation).

Regards,

Brian

Reply With Quote
  #5  
Old July 13th, 2004, 03:12 PM
adrapley adrapley is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Washington DC, USA
Posts: 20 adrapley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
As kiteless suggested, it's typically not good idea to store important information in cookies. Information stored in cookies are stored on the client machine, and the browser exchanges this information with the server in plain text. But, if you're not using SSL, passwords are even exchanged as plaing text upon login.

When using <CFAPPLICATOIN>, by default two cookies are set on the client, 1) Cookie.CFID and 2) Cookie.CFTOKEN. These two cookies store numbers that are unique to a visitor. These cookies help the CF server to determine which client and session variables stored on the server belong a user. By default, client variables are stored in the registry, and is a bad thing in windows, b/c if the registry becomes too big, it may become corrupt. In the CF administrator, you can specify how long to keep client variables before purging them.

You shouldn't have to set the password as a cookie or client variables. You should be able to set a variable called client.userid (using the value of the field in the db that is the primary key for a user).

Maybe in application.cfm, you can set <cfparam name="client.userid" default="0">. One use of <cfparam> checks to see if a variable is already defined, and if it isn't, sets a default value.

then you can do somehting like

<cfif client.userid>
<cflocation url="somepage.cfm">
</cfif>

Notice I didn't use an EQ here. If client.userid is any positive integer, then the condition will be true. By client.userid being defined, they have obviously been to the site before, so you can pull from the database, set session variables, or perform some other action based on client.userid and they possibly perform another <cflocation>


A Note About Passwords In General

When storing passwords in the database, I typically use CF's Hash() function. You can not decrypt what the Hash() function has encrypted. To compare passwords, I typically Hash() what's passed at login and compared it to the encrypted string that's stored in the database. Since you can not decrypt what's stored in the database, you can not retrieve a user's password, but instead, what I usually do is generate a new one, an automated process.

One More Note

While complex objects (structures, arrays, queries) can not be stored as client variables, they can be converted to wddx packets and the wddx packet can be stored as a client variable since a wddx packet is simply an XML parsed string.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Safely storing a password


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway