473,385 Members | 1,908 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.

client side secrets

Hi,

This maybe more of a Javascript question than PHP, but as it requires some
understanding about what is sent over the line and what not, I assume this
is the better forum to ask.

I'm building a php app, and I'm planning to use md5/hmac-md5 for the
password protection. I cannot always use ssl, for that would simplify
things, and provide much better protection.

For this to work, I need to generate a secret (no problem), and pass this to
the client (this can be done by using the md5 of the password as a symmetric
key). So far so good.

Now, to prevent someone having to type his password any time he wants to
change a password (which is doable for ordinary users, but not for admins
who do this routinely for other users), I want this secret stored in the
client, available to javascript, between pages.

A cookie isn't an option, as that's sent over the line. I was thinking to
put the application a (hidden)frame, and the secret in a variable in
another, but I have the feeling there should be an easier way. Does anyone
have an idea?

Thanks,
Bas
Jul 16 '05 #1
5 3378
> Now, to prevent someone having to type his password any time he wants to
change a password (which is doable for ordinary users, but not for admins
who do this routinely for other users), I want this secret stored in the
client, available to javascript, between pages.
Just use a different script for admins - if they are logged in as an admin
they can change any password in the database just by typing the new one in,
and possibly the admin's own old password to verify that it is an admin
logged in. Normal users can only change theirs if they can type their old
one in first and then their new one.
A cookie isn't an option, as that's sent over the line. I was thinking to
put the application a (hidden)frame, and the secret in a variable in
another, but I have the feeling there should be an easier way. Does anyone
have an idea?


A hidden frame will still be accessible by viewing the source so that is not
going to provide any sort of security over a cookie.

What I do with passwords is they log in (without ssl, but security isn't
hugely important), PHP then checks that password against the value in the
database, and if it matches then use sessions (either in a cookie or as a
query string on the url) which keeps the details of what access they have on
the server - a much safer place for it to be. Every other page then just
checks the session data to make sure it is a logged on user. For changing
passwords, just ask them for their old one just to verify it is the user
changing it and they haven't just left it logged in somewhere. For admins
though, PHP can deal with verifying that it is a admin that is logged in and
the admin can change any password.

But most importantly, using javascript for password validation / storage is
not at all secure, and theres no reason you would need to do it. Keep the
password server-side except when the user has to enter the password - but
never send a password back to the page. Also, once you recieve the password
in your PHP script, hash it and only ever use the hash values - the script
should never see the password again.

Its a bit of a rethink to what you're doing, but seems to be a better way to
do what you're doing.

David
Jul 16 '05 #2
Just use a different script for admins - if they are logged in as an admin
they can change any password in the database just by typing the new one in, and possibly the admin's own old password to verify that it is an admin
logged in. Normal users can only change theirs if they can type their old
one in first and then their new one. The way I see it is the following: everyone (including admins) have to type
their own password to change it. This is the usual way of doing things. But
admins also routinely change passwords of other (new) users. To have
them type their password at every opportunity is a bit much.
A hidden frame will still be accessible by viewing the source so that is not going to provide any sort of security over a cookie. That isn't really a problem. If they can get to the browser physically, they
can also install a keylogger or something. That's beyond my control. What I
worry about is about the communication. The scheme I was thinking about (for
encryption I use hmac-md5):

Client --------------------------------- Server

login:
*request login screen -------->
*generate secret and keep it in
sessionvariable
*encrypt secret with md5sum(pwd)
as key
<-------- *send encrypted secret
*decrypt secret if password
is entered correctly
*store secret (locally) during
session
*send md5(md5(password)
+sessionid) to verify login -------->
*if md5(md5(password)+sessionid)
matches with expectation, login
is succesful, else retry

password change (admin changes other users' passwords):
*encrypt(md5(newpassword))
using secret as key -------->
*if md5(oldpwd) matches, the
md5(newpwd) is stored

This way: the password is never sent during login. The md5(password) is only
sent hashed with the sessionid. This ensures that even that cannot be
snooped.
The md5(password) is only sent during password change, and even that's
encrypted.
But most importantly, using javascript for password validation / storage is not at all secure, and theres no reason you would need to do it. Keep the

I don't want do that. I only use the password to generate the md5(password).
That's what I store in the DB, serverside. The client side doesn't even
store that during the session, I only want to use the secret, which is only
valid for one session.

Hope this clears things up a bit. Now I still need an elegant way to store
the secret on the client between requests :)

Regards,
Bas
Jul 16 '05 #3
> The way I see it is the following: everyone (including admins) have to
type
their own password to change it. This is the usual way of doing things. But admins also routinely change passwords of other (new) users. To have
them type their password at every opportunity is a bit much.
Well you can decide that in your own code - if you don't want admins to have
to enter their password, just serve admins with a different form that just
asks for username and new password, and if they are logged in as admin
assume they have the access to do so.
That isn't really a problem. If they can get to the browser physically, they can also install a keylogger or something. That's beyond my control. What I worry about is about the communication. The scheme I was thinking about (for encryption I use hmac-md5):
Ah right - so basically you want to encrypt with javascript before the
password leaves the computer, and use this key as the salt for the
encryption? If this is right, I understand what you're trying to do, and in
which case my previous suggestion won't do it as you realised.

Unfortunately no idea how you'd do it - a lot of people have javascript
turned off, and as far as i'm aware md5 functions aren't standard in
javascript so I think you could have a lot of problem with doing it.
Personally my site doesn't need particularly high security so I send it
unencrypted at the first stage, and keep it encrypted from then on. Even if
you can get something in javascript, it will probably be a lot of effort if
you want it to work on all browsers, and really if you need good security
you should use ssl, if you don't its probably not worth the effort.
Hope this clears things up a bit. Now I still need an elegant way to store
the secret on the client between requests :)

You could store it anywhere in javascript really - putting it in a hidden
frame will be no more difficult for someone to see than putting it in the
middle of the main page. If you are generating some sort of random key to
use each time, then it really doesn't matter whether the user can see it or
not. You could just use the session ID really, they are unique and
accessible to both server and client easily.

If you do still want to try though then I can't be much more help.

Sorry

David
Jul 16 '05 #4
> Unfortunately no idea how you'd do it - a lot of people have javascript
turned off, and as far as i'm aware md5 functions aren't standard in
javascript so I think you could have a lot of problem with doing it. You can download those here: http://pajhome.org.uk/crypt/md5/
I'd only have to port them to php as that doesn't support hmac-md5, but the
code can be pretty much reused.
You could store it anywhere in javascript really - putting it in a hidden
frame will be no more difficult for someone to see than putting it in the
middle of the main page. If you are generating some sort of random key to
use each time, then it really doesn't matter whether the user can see it or not. You could just use the session ID really, they are unique and
accessible to both server and client easily. I don't care if the user sees it or not. He has the password anyway. It's
the man in the middle I'm worried about. And he definately has the
sessionid.
If you do still want to try though then I can't be much more help.

Thanks for your time anyway :) Your comment made me check and spot some
things I have to think about.

Regards,
Bas
Jul 16 '05 #5
> You can download those here: http://pajhome.org.uk/crypt/md5/
I'd only have to port them to php as that doesn't support hmac-md5, but the code can be pretty much reused.
Ah yeah, looks quite good. I never realised that the code for MD5 was
actually available, which is why I didn't think you'd be easily able to add
it in javascript.
Thanks for your time anyway :) Your comment made me check and spot some
things I have to think about.


OK. Sorry if i've been a bit negative - I do now see both what you are
trying to do and how you are going to do it. Hope its helped even in just a
little way.

Good luck

David
Jul 16 '05 #6

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

Similar topics

9
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side...
11
by: Tom Leylan | last post by:
(I posted this in languages.vb also... I can't figure out where things go if you use a little of a lot of things) Hi all... I'm looking for an example (or a pointer to one) related to the...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
6
by: Ken Allen | last post by:
I am relatively new to .Net and C#, but I hav ebeen programing in other languages and done some COM work for a number of years. I am attempting to understand how to map an older program...
4
by: | last post by:
Hello Guys, I am using the validation controls to validate my data. But the problem is "The page is still being posted to server". I want to get rid of the round trips to server. Are there...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
10
by: Ben | last post by:
Hi, I made an application in classic asp (reservation of books and video stuffs for students) and want to migrate to asp.net. The user has to chose a date, then pushung on a submit button. The...
3
by: Simon Brooke | last post by:
I've been doing XSL transforms, converting XML to HTML, server side since 2000. In those days, clients which could do the transformation client side didn't exist, so whether to transform...
0
by: The 101 ROMANTIC SECRETS and TECHNICS | last post by:
The 101 ROMANTIC SECRETS and TECHNICS This SECRETS and TECHNICS are right for you if: 1. How to try to get a person you want, 2. To make your partner love you more an more. If you want to...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.