-3

I have created a form which will take input from user in the form of password. Then I want to encode it at client side and then decrypt it on server side. So wanted to encode using JS and decode using PHP. So wrote JS code mentioned below:

<script>
    function doThis()
    {
        document.myform.password.value = "hello" + document.myform.password.value; // Considering this as encoded data
        return true;
    }
</script>

When I try to encode this data it causes issue, which is because I am not using right encoding algorithm. After a bit of search I found one encode decode methods base64_decode and base64_encode, both are of PHP. So I want to know if there is any way I can encode in JS and decode in PHP so that i can get correct data. On server I am using below code:

$password = base64_decode($_POST['password']);

HTML code:

<form name="myform" onsubmit="return doThis()" action="admin.php" method="post">
<input type="password" name="password" id='password'>
<input type="submit" value="SignIn">

This will help in protecting password while sending from client to server. I don't want to use SSL, but still want to protect password from fishing or other kind of attacks.

Please help understand this with example of code. If i can use any other encryption algorithm, please help me understand using code. Also can achieve this only through PHP?, i googled and found that we need JS for doing it, as need to encode at client side, but as using PHP so want to decode it using PHP.

Sumit Bijvani
  • 8,154
  • 17
  • 50
  • 82
Mitesh Sharma
  • 261
  • 4
  • 14
  • 4
    This is utterly pointless. Use an SSL connection and you get the encryption for "Free". By doing the crypt in JS you have to include the crypt code anyways, so you've essentially provided "security" in about the same way that a piece of wet toilet paper helps in "cleaning up" after a hurricane. – Marc B Mar 07 '13 at 18:39
  • Why don't you want to use SSL? It works. What you're trying to do won't. – Reinstate Monica -- notmaynard Mar 07 '13 at 18:46
  • Thanks, but i don't want to spend extra money for buying SSL. Sorry if my question is silly, but does buying SSL will encrypt all my data? As i just want to encrypt decrypt my password, as that is sensitive so thought of this approach. – Mitesh Sharma Mar 08 '13 at 08:02

1 Answers1

-1

Have you looked here:

How can you encode a string to Base64 in JavaScript?

This should do the javascript part of the question

Community
  • 1
  • 1
André Schild
  • 4,592
  • 5
  • 28
  • 42