2

I am working with express js. I have a modal form which has username and password field. i am posting the form data using ajax call. everything works fine but only issue is the username and password which i am entering are visible in post header, so is there any way in jquery to encrypt the form data before submitting..

here is my code

 $("#login").click(function(){
     var d=$("#form-1").serialize();
    // console.log("serialize data=",d);
    $.ajax({
        method : 'POST',
        url  :'/login',
        data :d ,
        success:function(response){
            console.log("response=",response.message);
            if (response.message=='success'){
                $("#msg").hide();
                 $('#myModal').modal('toggle');
                console.log('in if 83');
                }
            else
                {
                console.log("in else");
                $("#msg").text("invalid username or password");
                $("#msg").show();
                }

        }
    });   

  });
Pritam Kale
  • 33
  • 1
  • 1
  • 4

2 Answers2

4

You should think about using the HTTPS protocol, then this gets encrypted automatically.

For testing or if you are aware of the risks + pros and cons you can use a self signed SSL certificate: How to create a self-signed certificate with openssl?

For production you should use a valid SSL certificate, you either have to buy it or use one off those free providers.

Community
  • 1
  • 1
m4lt3
  • 465
  • 2
  • 15
  • how should i achieve HTTPS protocol in my example...what i need to do? – Pritam Kale Jun 02 '15 at 11:46
  • You need to add the valid or self signed certificate to your webserver, enable the https connection and use for your ajax call the https connection. A specific answer would be much to complex, but you can find everything you need, on stackoverflow or some else in the internet. – m4lt3 Jun 02 '15 at 11:49
0

Generally it is recommended to use SSL (Secure Socket Layer) when you are transmitting data that you don't want any third party to sniff. The data will be encrypted by browser before transmitting and can only be decrypted by your server - using public key/private key mechanism.

obai
  • 399
  • 5
  • 14