views:

110

answers:

3

hey guys, i wonder if there's a secure way to deliver a password with an URL (like ?p=mypassword) how can i encrypt and decrypt such a password so it's secure.

i guess md5 is not working in my case because the password must still be readable. It's an FTP passwort which gets passes along to the ftp_connect. i think md5 doesn't work in this case because i have to query if a string matches the md5 hash. however i can't do that in my case.

any ideas?

+6  A: 

Erm: Send via POST + SSL

SSL ensures that the password can not easily be read by third parties while in transit. Sending it via POST simply sends the variable to the server outside the URL and keeps it out of the server logs (hopefully). This will do an alright job hiding it from browser history or people sniffing HTTP.

But then, doesn't ftp_login() send this plaintext when using ftp_connect() making a mockery of the SSL in HTTP? Make sure you use ftp_ssl_connect() to your server afterwards. See the ftp_ssl_connect() PHP manual entry

Aiden Bell
In addition, it's good practice to make sure password parameters don't go into your webserver logs
nfm
@nfm - Thanks :) Added.
Aiden Bell
+2  A: 

If your site accepts an encrypted password in the query string, that encrypted string - though unreadable - is functionally no different than the password itself.

If my password to enter the CIA is "password", but they'll let me in if I say "5f4dcc3b5aa765d61d8327deb882cf99", both strings function as my password and both need to be protected.

ceejayoz
+1, good point wrt equality of the strings ... though a __brute forcer may disagree__ with that equality ;)
Aiden Bell
Good point, but he seems to be mainly worried about someone intercepting the query string somewhere.
ceejayoz
A: 

Instead of using a one way hash (MD5, SHA1). I think you need an encrypt-decrypt function. Take a look at this http://www.php.net/manual/en/function.mcrypt-encrypt.php.

The above example, you can encrypt using the key and pass the password in the URL. Once the password is received by PHP, you can then decrypt the password and use it to connect FTP. The only limitation is that the key will have to be available on the PHP server and wherever you generate the URL. There are also limits on the size of the string but I think you will be within those limits generally.

Pasta
As an user suggested, POST over SSL is the most secure/reliable method. Use the encrypt-decrypt method if you have to use GET requests.
Pasta
do i have to intall anything or does it come with php?
This comes with PHP, you might have to enable this extension if it is not already enabled http://www.php.net/manual/en/mcrypt.setup.php
Pasta