By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,700 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,700 IT Pros & Developers. It's quick & easy.

Encrypting a javascript variable

P: 51
I have entered a value in a text box , i have called a javascript function.
There i have written as under:
[ var old=document.frm.old.value;
alert(old1); ]

I am not getting any error message in the javascript , neither i am getting the alert message.
if i remove the crypt function line and display alert message as alert(old),
then i am hetting the value of the textbox in that variable. So, i think there is something wrong in my crypt function. So, Could anyone tell me the correct syntax for a crypt function that works perfectly?

Thanks & Regards,
pavan .
Jun 20 '08 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027
Show your crypt function. Note that encrypting something using JavaScript for the purposes of hiding is not foolproof by any means and can be decrypted, sometimes quite easily.
Jun 20 '08 #2

P: 51
hi ,
My entire javascript function is as under .
Expand|Select|Wrap|Line Numbers
  1.   function call(frm)
  2.        {
  3.                 var old=document.frm.old.value;
  4.                     old1=crypt([old,key]);
  5.                     alert(old1);
  6.                 var new1=document.frm.new1.value;
  7.                 var new2=document.frm.new2.value;
  9.                 if(old=="" || new1=="" || new2=="")
  10.                 {
  11.             alert("Enter values");
  12.                         return;
  13.         }
  14.                 else 
  15.                 {
  16.               if(old!="$old_password")
  17.                       {
  18.                            alert("You have entered wrong old password!!! Try Again");
  19.                            return;
  20.                       }
  21.                       else
  22.                       {
  23.                 if(new1==new2)
  24.                             {   
  25.                  var url="$session_id&USERID=$UID&pass=1";
  26.                                  document.frm.action=url;
  27.                                  document.frm.submit();
  28.                 }
  29.                              else
  30.                              {
  31.                  alert("The two new passwords you have entered do not match!!! Enter again!!!");
  32.                                  return;
  33.                  }
  34.               }
  36.                 }
  37.        }

In the above code $old_password is the already existing password in the database. $old_password is a perl variable. old_password is already encrypted in the database for security reasons. I have caught that encrypted value in the perl variable $old_password, but there is no decrypt function in perl.
So, i want to encrypt the javascript variable old. In the above code the javascript encrypt function crypt() is not working. So, please tell me a way to encrypt my javascript variable.

Thanks & Regards,
Jun 20 '08 #3

Expert Mod 15k+
P: 16,027
You will have to use the same encryption algorithm used for encrypting the password in Perl. I suggest that you make this check in Perl rather than JavaScript. You can make an Ajax request if you want to avoid page reload.
Jun 20 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.