/    Sign up×
Community /Pin to ProfileBookmark

md5 a form value before transmission?

Ok. Just been tinkering with the md5() on forms and came across a bit of a puzzler (for me anyway). How do you md5() the value of a form field before it is sent to another page or a database?

It can’t be done (so far as I can see) by saying $formvalue = md5($formvalue); either before or after the form its self because the php has already been processed and no longer has anything to do with the html until the form data has been sent to the next page which means it has already been sent over the line and is now too late to hash it because it’d be pointless by then. Seems a bit of a catch 22 really.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@sciguyryanAug 16.2004 — I don't think you can and there is no point anyway, just do it at the start of the script:

[code=php]
<?php
$var = $_POST["Password"];
$var = md5($var);
?>
[/code]




Hope that helps,


RyanJ
Copy linkTweet thisAlerts:
@AdamGundryAug 16.2004 — If you want to hash the password before it is transmitted over a network (which may be worth doing if you're concerned about eavesdropping, though SSL might be better) you can use a JavaScript MD5 implementation such as [url=http://pajhome.org.uk/crypt/md5/]this one[/url]. Bear in mind that some users may have JS disabled, so you may need to think about the login processing on the server side a little more (determine if the password was hashed, and hash it if necessary).

If you simply want to hash the password to compare it to (or store it in) a database record, you can put what Ryan suggested at the start of the script.

Adam
Copy linkTweet thisAlerts:
@Stephen_PhilbinauthorAug 16.2004 — I'd rather not use javascript in such a key part of the site. SSL seems a bit overkill too, I guess passwords as plain text will have to do.
×

Success!

Help @Stephen_Philbin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...