473,406 Members | 2,894 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,406 software developers and data experts.

secure login form

Hello,

while I'm developing sites for some time I never coded a login form with
security in mind.

I was wondering what guidelines there are.

For my point of view I'm thinking of using md5 passwords (it's an one
way function right?) in db. Is this a correct approach?

Then, if I'm permitted by the server admin I want to use https. Is it as
simple as puting the login form in the httpdocs of the https server an
when login is successful then I just set a session variable? Will I then
be able to read this from a page under http?

Thanks in advance.
Jun 27 '08 #1
8 2854
Harris Kosmidhs schreef:
Hello,
Hi,
>
while I'm developing sites for some time I never coded a login form with
security in mind.

I was wondering what guidelines there are.

For my point of view I'm thinking of using md5 passwords (it's an one
way function right?) in db. Is this a correct approach?
What is it you want to protect against excactly?
If you want the avoid the man-in-the-middle eavesdropping on you: Then
you need https, as you described.

If you are afraid the username/password you store in your database is
hacked somehow, then it can make sense to store them with an md5 hash,
which is one-way encryption indeed.
So that means you, as admin of the database, cannot tell what the
password is since you only see the md5 hash.
You can check of course if a provided password 'translates' to the
stored md5.

Personally, I stopped storing my passwords with a md5 hash in database.
I figured that if somebody can enter my database at will, my site is
hopelessly cracked beyound repair anyway. ;-)

>
Then, if I'm permitted by the server admin I want to use https. Is it as
simple as puting the login form in the httpdocs of the https server an
when login is successful then I just set a session variable? Will I then
be able to read this from a page under http?
You have NO shared session between you http and https pages.
So if you need that, you must build that yourself somehow.
(You can propagate the sessionid from http to https via a form, and let
the receiving script use that sessionid for its https session. But be
carefull and always remember that your client can set ANY value for
PHPSESSID easily). Always try to hack your own site with all the
knowledge you have about its internals.

Besides that, you also might consider getting a security audit.
>
Thanks in advance.
Good luck.

Regards,
Erwin Moller
Jun 27 '08 #2
Harris Kosmidhs wrote:
Hello,

while I'm developing sites for some time I never coded a login form with
security in mind.

I was wondering what guidelines there are.

For my point of view I'm thinking of using md5 passwords (it's an one
way function right?) in db. Is this a correct approach?
Yes. It certainly does not hurt. Better "salt" your hashes (by appending
a known, self chosen string to it). I can check for md5('password'), but
it is harder to check for md5('SiteNamepassword') if I do not know that
'SiteName' is the salt of your hash. Also note that hashes are not
necessarily different for different passwords. So the password field in
the database must not be unique if you use hashes. But it must not be
unique anyway.
But this is mainly database security. If your PHP site calculates the
hashes, the password is already sent over the big bad internet to your
server. That is where https comes in.
>
Then, if I'm permitted by the server admin I want to use https. Is it as
simple as puting the login form in the httpdocs of the https server an
when login is successful then I just set a session variable? Will I then
be able to read this from a page under http?
These are great questions to system administrators. You will need a
separate IP address for each https site, but you can run "normal" http
on the same IP address. So if you just have one site, one address will
do. In the web server, you 'll have to configure another directory that
becomes the root of the https site. Just see it as a separate site. You
can, however, define symlinks to parts the regular site. This can be
useful for sharing directories like CSS, images, etc. that contain
static content and are also needed in the https site.

One note of care: if you use cookie-based sessions (meaning that the
session ID is in a cookie), you can mark your cookies as secure. This
will prevent browsers from sending them to the non-secure part. Off
course, the PHP manual has some nice info on the matter as well. See,
for instance, session_destroy and session_regenerate_id. Read especially
the last one. A net search for "session fixation" and "session
hijacking" also gives some valuable insight.

Best regards
Jun 27 '08 #3
On 5 Jun, 15:10, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
If you are afraid the username/password you store in your database is
hacked somehow, then it can make sense to store them with an md5 hash,
which is one-way encryption indeed.
So that means you, as admin of the database, cannot tell what the
password is since you only see the md5 hash.
A salt is required here. There are md5 lookup dictionaries on the web
that will give you the "trivial" password that led to a particular md5
hash.

Trivial includes peoples names and lots of other commonly used
passwords. The salt can be stored with the md5 hash, it still stops
the reverse md5 process from being successful.
Jun 27 '08 #4
Erwin Moller wrote:
Harris Kosmidhs schreef:
>Hello,

Hi,
>>
while I'm developing sites for some time I never coded a login form
with security in mind.

I was wondering what guidelines there are.

For my point of view I'm thinking of using md5 passwords (it's an one
way function right?) in db. Is this a correct approach?

What is it you want to protect against excactly?
If you want the avoid the man-in-the-middle eavesdropping on you: Then
you need https, as you described.

If you are afraid the username/password you store in your database is
hacked somehow, then it can make sense to store them with an md5 hash,
which is one-way encryption indeed.
So that means you, as admin of the database, cannot tell what the
password is since you only see the md5 hash.
You can check of course if a provided password 'translates' to the
stored md5.

Personally, I stopped storing my passwords with a md5 hash in database.
I figured that if somebody can enter my database at will, my site is
hopelessly cracked beyound repair anyway. ;-)
And what's your approach now? Clean passwords as text db fields?
>
>>
Then, if I'm permitted by the server admin I want to use https. Is it
as simple as puting the login form in the httpdocs of the https server
an when login is successful then I just set a session variable? Will I
then be able to read this from a page under http?

You have NO shared session between you http and https pages.
So if you need that, you must build that yourself somehow.
(You can propagate the sessionid from http to https via a form, and let
the receiving script use that sessionid for its https session. But be
carefull and always remember that your client can set ANY value for
PHPSESSID easily). Always try to hack your own site with all the
knowledge you have about its internals.
What should look like what I have to build? Let's say you press "log
in". It load the (https) login.php which finds out you are a user. Then?
A header('http://example.org/loginnext.php?id=$userid') ??
Is there a way not to pass id with GET but with POST without user
submitting the form himself?

thanks
Jun 27 '08 #5
Harris Kosmidhs schreef:
Erwin Moller wrote:
>Harris Kosmidhs schreef:
>>Hello,

Hi,
>>>
while I'm developing sites for some time I never coded a login form
with security in mind.

I was wondering what guidelines there are.

For my point of view I'm thinking of using md5 passwords (it's an one
way function right?) in db. Is this a correct approach?

What is it you want to protect against excactly?
If you want the avoid the man-in-the-middle eavesdropping on you: Then
you need https, as you described.

If you are afraid the username/password you store in your database is
hacked somehow, then it can make sense to store them with an md5 hash,
which is one-way encryption indeed.
So that means you, as admin of the database, cannot tell what the
password is since you only see the md5 hash.
You can check of course if a provided password 'translates' to the
stored md5.

Personally, I stopped storing my passwords with a md5 hash in database.
I figured that if somebody can enter my database at will, my site is
hopelessly cracked beyound repair anyway. ;-)

And what's your approach now? Clean passwords as text db fields?
Yes.
>
>>
>>>
Then, if I'm permitted by the server admin I want to use https. Is it
as simple as puting the login form in the httpdocs of the https
server an when login is successful then I just set a session
variable? Will I then be able to read this from a page under http?

You have NO shared session between you http and https pages.
So if you need that, you must build that yourself somehow.
(You can propagate the sessionid from http to https via a form, and
let the receiving script use that sessionid for its https session. But
be carefull and always remember that your client can set ANY value for
PHPSESSID easily). Always try to hack your own site with all the
knowledge you have about its internals.

What should look like what I have to build? Let's say you press "log
in". It load the (https) login.php which finds out you are a user. Then?
A header('http://example.org/loginnext.php?id=$userid') ??
Is there a way not to pass id with GET but with POST without user
submitting the form himself?
Well, I was assuming that both the http-domain AND the https domain were
on the same server.
If that is not the case, things will get more complicated, because
you'll have to build a system that uses a common session-storage for
different machines (using a database instead of serialized
session-array, which is default).

The important thing is (when using a common sessionstorageplace) to pass
around the sessionid.
eg, from http to https:
<form action="https://www.example.com/myhttps.php" method="post">
<input type="hidden" name="httpsessid" value="GJHGA577FKJ98FGKJ3">
<input type="submit">
</form>

From www.example.com/myhttps.php you can now pick up the passed
httpsessid from $_POST["httpsessid"] and use that one to pick up the
session under that name.

There are a lot of ins and outs, depending on your serverconfig, so be
sure you test everything you try.

I would advise you to first read through the relevant pages on php.net
so you have a firm understanding of how sessions work before building this.
Be sure how to name a session (PHPSESSID), how to overrule a name, when
sesisons are autostarted, etc etc.

Good luck.

Regards,
Erwin Moller
>
thanks
Jun 27 '08 #6
On Jun 5, 2:15 pm, Harris Kosmidhs <hkosm...@remove.me.softnet.tuc.gr>
wrote:
Hello,

while I'm developing sites for some time I never coded a login form with
security in mind.

I was wondering what guidelines there are.

For my point of view I'm thinking of using md5 passwords (it's an one
way function right?) in db. Is this a correct approach?

Then, if I'm permitted by the server admin I want to use https. Is it as
simple as puting the login form in the httpdocs of the https server an
when login is successful then I just set a session variable? Will I then
be able to read this from a page under http?

Thanks in advance.
sha1 is a stronger hash than md5, and actually runs faster in PHP -
but does require more storage - the intrinsic strength of the hash is
not nearly as important as **using a good salt**.

There's limited benefit in protecting the password very well, but the
session identifier (which could easily be sniffed from the http
exchanges). Also you should read up on session hijacking - regenerate
the session ID on a successful login.

C.
Jun 27 '08 #7
Storing MD5s instead of the actual passwords in the DB is a good idea,
you get user input (maybe add something), MD5 it and then compare it
to the db record.

HTTPS can be complex if you have the pages in seperate locations
(depends on server config), prbably an auto generated key base on tine
would be a good method to bridge between the locations, or just put a
redirect on the unsecure side to a secure login. If SSL it can be
both on the same place you can also do a check to see if SSL is being
used and restrict users who are not using it. (google for it)

---------------------------------

I was working on a better logins myself, I figured I could do it this
way:

1. user goes to site's index.php with a preset key http://mysite.com/index.php?pw=pass
- if index.php validates the password, it sets ap a session variable
that it has 'passed'. Now, regardless of pass or fail it still
redirects to the login.

3. Login operates as normal but will not even try to validate without
the session being set. After x number of failed attempts (recorded by
another session variable) it redirects to another (lame) page. Might
be fun to make the fail count random...

---------------------------

An alternative I've seen is to make a token generator for the client
(using python or some other common language) and have it generate the
token using a count, time, etc, along with MD5 or whatever. Then when
you click on it's icon it generates the URL with the token for the
site and calls the browser. Then the browser can validate.
Jun 27 '08 #8
On Jun 6, 9:04 pm, la...@portcommodore.com wrote:
Storing MD5s instead of the actual passwords in the DB is a good idea,
you get user input (maybe add something), MD5 it and then compare it
to the db record.

HTTPS can be complex if you have the pages in seperate locations
(depends on server config), prbably an auto generated key base on tine
would be a good method to bridge between the locations, or just put a
redirect on the unsecure side to a secure login. If SSL it can be
both on the same place you can also do a check to see if SSL is being
used and restrict users who are not using it. (google for it)

---------------------------------

I was working on a better logins myself, I figured I could do it this
way:

1. user goes to site's index.php with a preset keyhttp://mysite.com/index.php?pw=pass
- if index.php validates the password, it sets ap a session variable
that it has 'passed'. Now, regardless of pass or fail it still
redirects to the login.

3. Login operates as normal but will not even try to validate without
the session being set. After x number of failed attempts (recorded by
another session variable) it redirects to another (lame) page. Might
be fun to make the fail count random...
That might make sense if step 2 hadn't been omitted ;)
---------------------------

An alternative I've seen is to make a token generator for the client
(using python or some other common language) and have it generate the
token using a count, time, etc, along with MD5 or whatever. Then when
you click on it's icon it generates the URL with the token for the
site and calls the browser. Then the browser can validate.
There are 2 problems with this - 1) it requires the user to runs some
code outside of the browser, 2) using time as initialization vector/
salt/whatever for a hash is a very bad idea - its OK for reversible
encryption when you can decrypt and extract the time then work out the
difference from now.

There was a lengthy discussion recently on this NG regarding using
Javascript to create an MD5 hash using a server-side (session)
modifier which avoids these problems - have a Google.

C.
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: The Plankmeister | last post by:
Hi. I reaslise this is possibly considered off-topic, but I want to pick as many expert brains as possible. Apologies in advance.... I have a form on which I have a username and password box....
6
by: Sarah Tanembaum | last post by:
I was wondering if it is possible to create a secure database system using RDBMS(MySQL, Oracle, SQL*Server, PostgreSQL etc) and web scripting/programming language(Perl, PHP, Ruby, Java, ASP, etc)...
3
by: Aaron | last post by:
Hey, I have a question about how secure the following will be.... I want to have a login form that posts to itself, so when it loads it checks if there is a username and password on the query...
6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
0
by: Darrell G | last post by:
I am in need of some good advice ... Goal: I need to automatically log users of my website into a second website. Obstacles: The second website requires I "post" a form with specific...
2
by: Jason Smith | last post by:
I have recently designed an application in Ms Access with the folllowing security: 1) Database is split into a front-end / backend with linked tables 2) All modules are password protected 3)...
1
by: sharp2037 | last post by:
Hi Everyone, I am working on an ASP.net application and I have a homepage to which everyone visits of course and on that front page I have a user ID and password box and a login button. What...
2
by: raknin | last post by:
Hi, I am looking for a close package of secure login and registeration written in PHP.The package that I am looking for should have the following functionality I believe this is standard...
5
topher23
by: topher23 | last post by:
I've seen a lot of questions about how to make secure database passwords. I'm going to go over a method of encrypting a password using the MD5 encryption algorithm for maximum security. First,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.