views:

52

answers:

3

how can i implement a secure transfer from login form on client to server in php? i mean coding password and user ,something except using https.

+5  A: 

Use HTTPS.

... something except using https.

Er, hm.

Why are you avoiding SSL? It's really the most simple, straightforward way to do what you're trying to do.

Charles
because i don't want whole my site using https and if i just use 1 page with https and other pages with http,that https page will also be accessible using http. i need something like md5 data at client-side.
hd
He said **something except using https.**
Sarfraz
@hd I don't understand your reason. Why can't you have just one page accessed via HTTPS?
Col. Shrapnel
because using https make page loading slower and coding transferring data for all pages is not necessary on my site,the only page that should be coded is login page.
hd
@hd You are incorrect. You can make the login page accessible via HTTPS only, and the rest of the site accessible via plaintext. Use HTTPS like everybody else does.
EJP
@sAc, you are completely correct, but I believe he can be talked out of it! ;)
Charles
@hd, SSL is secure, effectively transparent, and *not* slow. It's the *best* solution you have to securing the transport of sensitive data between a client's browser and your server.
Charles
ok,consider my login page address is : https: //mydomain.com/login.php but have can i restrict calling this page to https and if user type: http: //mydomain.com/login.php couldn't access to login page?
hd
@hd just check $_SERVER['HTTPS'] variable. Or make the same check on the .htaccess level
Col. Shrapnel
@ ALL: thanks alot my friends,i think i got convinced to used https for login page,but just that page.thanks again for helping
hd
+1  A: 

You may encrypt (MD5/SHA etc) your password on the client side using some salt value before sending it to the server. However this is for sure not the best approach. This is just better than sending it plain text. Prefer https.

Gopi
MD5 and SHA aren't encryptions, they are digests. This is not a bad approach actually, but HTTPS is at least as good.
EJP
It _is_ a bad approach; it's no more secure than sending it unhashed. If the server is expecting a hashed password, then someone sniffing traffic will get the hash and can send it - exactly the same as if the password was sent unhashed.
El Yobo
Agreed. Thats why I said 'just better'. With this at least one advantage I can see is user is assured that the passwords are not stored as plaintext on the server.
Gopi
+3  A: 

HTTP Digest authentication can work without requiring SSL.

But it has the same problems as other HTTP authentication. E.g. there's no logout function, you can't control the look & feel of the login UI, no integration between login credentials and your application-specific user account data, etc.

I agree with @Charles -- just use HTTPS when sending sensitive data.


Re your comment:

At the start of your login.php script, check if the request is https and if not then redirect to the correct url.

if (!isset($_SERVER["HTTPS"])) {
  header("Location: https://mydomain.com/login.php");
}

Alternatively you could use an Apache rewrite rule:

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(login.php) https://%{SERVER_NAME}/$1 [L,R]

Also, remember that you don't care if the client read the page with the login form with plain http. You care if the client submits the form insecurely, because that's the request that contains the user's password. So the above advice applies if login.php is the script that processes the login form.

Bill Karwin
ok,consider my login page address is : https: //mydomain.com/login.phpbut have can i restrict calling this page to https and if user type:http: //mydomain.com/login.php couldn't access to login page?
hd
The digest mechanism can be implemented manually as well.
Col. Shrapnel
@Bill: thanks alot,it seems complete.
hd