473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Saving User login info in a cookie

realin
254 100+
hi guys,

i am adding remember me featre on my website, i just want to know that what is the fashion like ?

i believe the password and username both should be hashed, but for a successful recovering in future i need one of them to be matched with my database without having to be hashed, because hashing with md5 and sha1 takes time(correct me if i am wrong).

So my attempt is to encrypt username with some algorithm that can be reversed so that i can actually retreive user name in original form before comparing it with database.

this is not possible with md5 or sha1 either.

So please tell me what should be the approach :)

thanks a lot
Aug 8 '07 #1
9 1986
epots9
1,351 Expert 1GB
I think this can be of some assistance for encoding and decoding

hope it helps,
good luck
Aug 8 '07 #2
Atli
5,058 Expert 4TB
Hi.

I've done the same thing you'r doing a couple of times. What I did was, I saved the user's ID in the cookie, along with a SHA1 hash of the username and the password combined. The password is of course a SHA1 hash before hand so this makes a nice messy string that people won't be decoding any time soon.

That way I can simply have my database return a hash from the user with the given ID and try to match it.

Hashing does of course take time, but were talking about perhaps a millisecond at the most so I'm not excactly worried :)

Edit
Tested it on a 350mhz linux server, each run of the php sha1() function takes about 0,000073 seconds :)
Aug 8 '07 #3
realin
254 100+
I think this can be of some assistance for encoding and decoding

hope it helps,
good luck
Well that is a good idea and that is something which gmail followed or still follows, but it doesnt protects from a hacker attempt cause that is something which can be easy decoded, a simple algorithm of our own may be a cipher would take more time to break than this one.. but still a good idea..

let me know if you know something to do more with base64 encoding, i must mention it is very popular :)
thanks a lot mate !!

Hi.

I've done the same thing you'r doing a couple of times. What I did was, I saved the user's ID in the cookie, along with a SHA1 hash of the username and the password combined. The password is of course a SHA1 hash before hand so this makes a nice messy string that people won't be decoding any time soon.

That way I can simply have my database return a hash from the user with the given ID and try to match it.

Hashing does of course take time, but were talking about perhaps a millisecond at the most so I'm not excactly worried :)

Edit
Tested it on a 350mhz linux server, each run of the php sha1() function takes about 0,000073 seconds :)

but this must vary with the number of records, the more he records, heavier is the process and hence more are he resources, anyways will give it a try cause still my website gonna be at initial stage and when the number of users increases, i m sure i will come across something better till then :)

thanks a bunch
Aug 9 '07 #4
kovik
1,044 Expert 1GB
'Remember me' capabilities are never secure, but the MOST secure way that I've thought of to do it is to give them a randomly generated id that you store in the cookie. Each time that they are re-logged in and begin a new session, you use that generated id (as well as their username) to verify the user, then generate a new one for them. This way, if their cookies do get stolen, then don't run the risk of their password being given (even if it is hashed, it is still an unnecessary risk) and they don't really risk their random ID being taken, as the next time they login, that ID would become invalid anyway.
Aug 9 '07 #5
realin
254 100+
'Remember me' capabilities are never secure, but the MOST secure way that I've thought of to do it is to give them a randomly generated id that you store in the cookie. Each time that they are re-logged in and begin a new session, you use that generated id (as well as their username) to verify the user, then generate a new one for them. This way, if their cookies do get stolen, then don't run the risk of their password being given (even if it is hashed, it is still an unnecessary risk) and they don't really risk their random ID being taken, as the next time they login, that ID would become invalid anyway.

i agree i got this info last night from http://php.net
[php]
<?php

$Seperator = '--';
$uniqueID = 'Ju?hG&F0yh9?=/6*GVfd-d8u6f86hp';
$Data = 'Ahmet '.md5('123456789');

setcookie('VerifyUser', $Data.$Seperator.md5($Data.$uniqueID));

if ($_COOKIE) {
$Cut = explode($Seperator, $_COOKIE['VerifyUser']);
if (md5($Cut[0].$uniqueID) === $Cut[1]) {
$_COOKIE['VerifyUser'] = $Cut[0];
} else {
die('Cookie data is invalid!!!');
}
}

echo $_COOKIE['VerifyUser'];

?>[/php]

if i follow what u say then that means i gotta store that random id into my database along with the login credentials ?

is it so ? or make a single unique as shown in above code

recommend me please
Aug 9 '07 #6
realin
254 100+
Or a simple encoding using base64 can be this way.. atleast this will take some time to decode, will make it more complex .
[php]
<?php
$str="sachin";
$sp="--";
$str1= base64_encode(base64_encode($str).$sp.base64_encod e($str));


$str_a=explode("--",base64_decode($str1));
$username= base64_decode($str_a[0]);
?>[/php]

need suggestions guys.. Which technique is robust and efficient :)

thanks a bunch to everyone :)
Aug 9 '07 #7
Atli
5,058 Expert 4TB
but this must vary with the number of records, the more he records, heavier is the process and hence more are he resources, anyways will give it a try cause still my website gonna be at initial stage and when the number of users increases, i m sure i will come across something better till then :)

thanks a bunch
It doesn't matter how many records exist using this method, as I store the users ID as well as the SHA1 mess I created, I only need to fetch a single SHA1 hash for the user that has the userID in the cookie.

It's always a risk to store user info in cookies, but hashing something twice and throwing in another string the second time, thats pretty darn hard to break.
Especially if you'r thinking about usign base64 encoding, which a simple php function can decode.

Also, if you don't like storing the userID in the cokkie, you can always do what Volectricity suggested and create a disposable one randomly.
Aug 9 '07 #8
realin
254 100+
thanks a lot guys, with all you i am able to do these stuff :)

thanks a lot .
Aug 9 '07 #9
kovik
1,044 Expert 1GB
hashing something twice
Double hashing doesn't increase security. There are articles all over the internet in regards to it. Just FYI.
Aug 10 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Joshua Beall | last post by:
Hi All, What is the best way to use a cookie to remember a logged in user? Would you store the username and password in two separate cookies? Should the password be plain text? Hashed? Not...
3
by: Bill H | last post by:
I'm really new to Internet apps and such sorry, if this is a "duh" question. What is the standard approach to saving input from a form if on submit the database connection fails? I'm thinking...
18
by: | last post by:
Please help. After a number of wrong turns and experiments I need advice on login management system to secure our web pages without inconveniencing our visitors or our internal staff. What I...
5
by: Andrew Banks | last post by:
Using forms authentication in C# I usually use FormsAuthentication.RedirectFromLoginPage to log a user in as follows FormsAuthentication.RedirectFromLoginPage(id,false); How can I log a user...
2
by: Beginner | last post by:
I know this is an old question, but searching all over the internet plus several MS security conferences, still haven't got a straight anwser. Basically, the login.aspx is on one dedicated server...
12
by: Anon | last post by:
Hello All! I was wondering how I can go about saving the last string entered into a textbox. I would like to save username or pwd info in textboxes in my forms so that users don't have to...
1
by: Stef | last post by:
Hi people, I have a problem with cookies set via javascript. What I try to achieve is, when a user comes on the intranet, he can click on a link ( a simple href) that will set the content to...
7
by: monomaniac21 | last post by:
hi i have a php site which allows users to save a cookie on their computer which stores their user id details and allows them to auto- login. i'm wondering whether this is safe, is it...
3
wadro21
by: wadro21 | last post by:
I am trying to create a members only area where they can update there contact info in the company directory but only theirs. problem is i can't seem to get it where they can only update there on. i...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.