473,395 Members | 1,530 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,395 software developers and data experts.

(S.O.S) Only 4 the best programmers. About Javascript & PHP

Hi:

I have a problem:
I've a page that sends an encrypted password, using MD5, to a PHP
file, which is able to compare such MD5 encrypted password with an
encryption stored on a data base. But the encryption way, on mD5, on
JavaScript and PHP doesn't return the same value.
My questions are:
1. Aren't these methods the same? I mean, the implementation on
JavaScript and the implementation on PHP.

2. I could fix this by calling my .js file on my .php file. How can I
do this?

3. Does anyone know about an encryption method that return the same
value, on JavaScript and PHP?

Thank's a lot.

Alejo.
Jul 17 '05 #1
11 2136
Amilcar wrote:
Hi:

I have a problem:
I've a page that sends an encrypted password, using MD5, to a PHP
file, which is able to compare such MD5 encrypted password with an
encryption stored on a data base. But the encryption way, on mD5, on
JavaScript and PHP doesn't return the same value.
My questions are:
1. Aren't these methods the same? I mean, the implementation on
JavaScript and the implementation on PHP.

2. I could fix this by calling my .js file on my .php file. How can I
do this?

3. Does anyone know about an encryption method that return the same
value, on JavaScript and PHP?

Thank's a lot.

Alejo.

Mmmmm what a heavenly way to make a site totally inaccessable to users
without javascript, and I could respond to points in question but as I
wouldn't call myself one of the best "programmers" I wont, and this news
group is public, putting subject lines like that is only going to make
you look bad IMHO.

~Cameron
Jul 17 '05 #2
Amilcar wrote:
1. Aren't these methods the same? I mean, the implementation on
JavaScript and the implementation on PHP.
The algorithm is standard, RFC 1321, but the implementations may vary.
2. I could fix this by calling my .js file on my .php file. How can I
do this?
You can't.
3. Does anyone know about an encryption method that return the same
value, on JavaScript and PHP?


MD5 should - but remember it's not "an encryption method", it's a
one-way hash. Minor technicality ;-)

First off, work out where the error lies. At the end of the RFC are
some test values. Run these values through both JS and PHP and see
which one doesn't give you the correct value. If they both give you the
correct value (just a simple print(md5($value))) then it's something
else in your code broken.

MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz0123456789") =
d174ab98d277d9f5a5611c2c9f419d9f
MD5 ("123456789012345678901234567890123456789012345678 901234567890123456
78901234567890") = 57edf4a22be3c955ac49da2e2107b67a

Cheers,
Andy
Jul 17 '05 #3
Cameron wrote:
Mmmmm what a heavenly way to make a site totally inaccessable to users
without javascript, and I could respond to points in question but as I
wouldn't call myself one of the best "programmers" I wont, and this news
group is public, putting subject lines like that is only going to make
you look bad IMHO.


Dammit - given that I've just responded, does that look egotistical. If
so, I take it back. AMILCAR DON'T USE THE INFORMATION I PROVIDED, I
HAVE WITHDRAWN IT.
;-)

Cheers,
Andy
Jul 17 '05 #4
Andy Jeffries wrote:
Cameron wrote:
Mmmmm what a heavenly way to make a site totally inaccessable to users
without javascript, and I could respond to points in question but as I
wouldn't call myself one of the best "programmers" I wont, and this
news group is public, putting subject lines like that is only going to
make you look bad IMHO.

Dammit - given that I've just responded, does that look egotistical. If
so, I take it back. AMILCAR DON'T USE THE INFORMATION I PROVIDED, I
HAVE WITHDRAWN IT.
;-)

Cheers,
Andy


lol, nah just stick to, I thought the subject line was insulting so I
replied anyway ;)

~Cameron
Jul 17 '05 #5
Amilcar wrote:
I've a page that sends an encrypted password, using MD5, to a PHP
file, which is able to compare such MD5 encrypted password with an
encryption stored on a data base. But the encryption way, on mD5, on
JavaScript and PHP doesn't return the same value.
My questions are:
1. Aren't these methods the same? I mean, the implementation on
JavaScript and the implementation on PHP.
I guess (at least) one of the implementations is not doing it according
to the specifications.
RFC1321 ( @ http://www.faqs.org/rfcs/rfc1321.html ) has a few test cases
along with an implementation in C.
2. I could fix this by calling my .js file on my .php file. How can I
do this?
hehe, in all the tests I did, the PHP implementation has never left me
down :)

Get a working JS implementation and let the browser use that one.
Have the server use PHP's implementation.
3. Does anyone know about an encryption method that return the same
value, on JavaScript and PHP?


You might want to check this page for a JavaScript MD5 implementation:
http://pajhome.org.uk/crypt/md5/index.html
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #6
I see a problem with your security scheme that makes the md5 hash almost
irrelevant. However, I can think of 5 programmers off the top of my
head who are better than me, so I guess I can't help you.
Jul 17 '05 #7
Amilcar wrote:

I've a page that sends an encrypted password, using MD5, to a PHP
file, which is able to compare such MD5 encrypted password with an
encryption stored on a data base. But the encryption way, on mD5, on
JavaScript and PHP doesn't return the same value.
My questions are:
1. Aren't these methods the same? I mean, the implementation on
JavaScript and the implementation on PHP.

2. I could fix this by calling my .js file on my .php file. How can I
do this?

3. Does anyone know about an encryption method that return the same
value, on JavaScript and PHP?


Yeah, ego thing aside, I just tested a Javascript (IE6/Win98) md5 hash and a PHP
one. They both came out the same (though it's quite possible different browsers
will implement it differently). Before you think too hard about solutions, I'd
make sure you're using the same text for both. Make sure something stupid is
not going on, like unintentional backslashes in the text or sending "Array()"
instead of an array element or any of the common errors that you might be
overlooking.

Once you figure out what's wrong and how to fix it, you might want to reconsider
using Javascript :o)

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #8
Who knows? Perhaps he's using a random challenge value. Then again, if I can
see the plaintext traffic then I can just steal the cookie and hijack the
session. All in all it's pretty pointless.

Uzytkownik "Bruce Lewis" <br*****@yahoo.com> napisal w wiadomosci
news:nm*************@mass-toolpike.mit.edu...
I see a problem with your security scheme that makes the md5 hash almost
irrelevant. However, I can think of 5 programmers off the top of my
head who are better than me, so I guess I can't help you.

Jul 17 '05 #9
I've a page that sends an encrypted password, using MD5, to a PHP
file, which is able to compare such MD5 encrypted password with an
encryption stored on a data base.
So basically you have a db of hashed passwords, and not like most
password auth stuff that's used on most webpages, you want to hash
the password -before- it's sent to the server, right?
JavaScript and PHP doesn't return the same value.
This is due to how it's implemented. If you use the md5-function
of PHP, that will yield the correct result. So the problem surely
lies in the javascript. So check it for errors.
1. Aren't these methods the same? I mean, the implementation on
JavaScript and the implementation on PHP.
MD5 is an algorithm, a one-way hash function. It's standarized,
so what's wrong here is it's implementation, probably in the js.
2. I could fix this by calling my .js file on my .php file. How can I
do this?
I'm not sure I know what you are talking about, but if you mean using
the algorithm used in your js in the execution of your php-script, then
the answer is no. It's not possible. And it wouldn't be a fix. It would
most probably mean that you'd be using a broken algorithm, since I'm
pretty convinced that it's your js algo and not the php md5 fu that's
broke here. (You are using the php md5 fu, and not your own fu, right?!)
3. Does anyone know about an encryption method that return the same
value, on JavaScript and PHP?
Yes. All of them, if they are implemented correctly. You problem is that
the client side (js) and the server side (php) algorithms aren't doing
the same, and as I've said a few times now, most probably the js.
But I'm not sure if you need to hash the password on the client side.
Or, actually, I know you don't, since it doesn't add security. See, I
bet you want to hash the password before you send it, to hide it from
being sniffed by someone, somewhere. But if you send the md5 hash of the
pwd, then the hash becomes the pwd as far as the server is conserned.
So if someone sniff the md5 hash of the pwd, they can use it at a later
time as the password.

The reason you want to hash the password in the first place, is to
protect it from being retrieved from the server by a hacker, and then
used by that hacker later. The security lies in that the user knows the
password, and the server knows it's md5 hash. So if anyone gets hold of
the md5 hash, it's totally useless, since you cant feed it to the server.
The server would hash it, and compare it, and the hash of the hash, would
not match the hash (of the password) of course.

So hasing the password -before- you send it to the server, would greatly
lower the security of your system.

I can only see one good reason to hash the password before you send it,
and that is to protect the password itself. What you'd need to do then,
is to hash it (with js) before you send it, and then hash it again at the
server. So what the server is having stored, and is doing it's compares
against, is a hash og the hash of the password. But as I said earlier,
this would not stop anyone from sniffing the (hash of the) password, and
using it later towards the server. It would only prohibit the sniffer of
knowing what your original pass phrase was. Which, of course, could have
some value of its own.

A better way of achieving what I suspect you want, is to use an encrypted
channel between the client and the host, using SSL (https://). This is
a whole other ballgame though...
Thank's a lot.


Your welcome :-)

--
Fred H

void FredH::Contact() {
TextToSpeach.say("frode at age dee dee dot en oh");
}
Jul 17 '05 #10

You could use SHA1 instead of MD5. SHA1 calculates a 160 bit hash
(40 hex chars), opposed to MD5's 128 bits hash (32 hex chars). The
security of SHA1 is considered better than that of MD5.

PHP has a SHA1 fu, called, yeah, sha1(). A sha1 js can be found here:
http://pajhome.org.uk/crypt/md5/sha1src.html

Good luck.
Jul 17 '05 #11
Amilcar wrote:
Hi:

I have a problem:
I've a page that sends an encrypted password, using MD5, to a PHP
file, which is able to compare such MD5 encrypted password with an
encryption stored on a data base. But the encryption way, on mD5, on
JavaScript and PHP doesn't return the same value.
My questions are:
1. Aren't these methods the same? I mean, the implementation on
JavaScript and the implementation on PHP.

2. I could fix this by calling my .js file on my .php file. How can I
do this?

3. Does anyone know about an encryption method that return the same
value, on JavaScript and PHP?

Thank's a lot.

Alejo.


OK, and what about '4 the best programmers' part!

Jul 17 '05 #12

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

Similar topics

11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
5
by: nivas.meda | last post by:
Hi, I have an excel sheet with a graph and cells.If i change the value in the excel cells the graph will reflect.Now i am going to implement this functionality in html page.I successfully saved...
9
by: optimistx | last post by:
Which url in your opinion would be a good or even the best example of javascript usage in a set of pages at least say 10 or more pages? How to use css, how to split js-code to files, how to code...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
2
by: Nathan Sokalski | last post by:
I am moving my website from my machine to my webhost, and need some help with what extra files I need to include due to the fact that I used AJAX in my site. Everything on the site is obviously...
14
by: Steve | last post by:
Several textbooks, including Javascript for Dummies (2005), show the "i=++i" method of incrementing a variable. I have been using this method but I have been recently informed by some experts in...
4
by: pmactdot | last post by:
Hi, I'm looking for some assistance on a case study...I have two arrays <head>: one for daily special dish name, second for the daily dish description, then I have two document.write: a daily...
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
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.