Encrypting a javascript variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pavanponnapalli
    New Member
    • May 2008
    • 51

    Encrypting a javascript variable

    hi,
    I have entered a value in a text box , i have called a javascript function.
    There i have written as under:
    [ var old=document.fr m.old.value;
    old1=crypt([old,key]);
    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 .
    Last edited by pavanponnapalli; Jun 20 '08, 10:03 AM. Reason: want to change the title
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    • pavanponnapalli
      New Member
      • May 2008
      • 51

      #3
      hi ,
      My entire javascript function is as under .
      [code=javascript] function call(frm)
      {
      var old=document.fr m.old.value;
      old1=crypt([old,key]);
      alert(old1);
      var new1=document.f rm.new1.value;
      var new2=document.f rm.new2.value;

      if(old=="" || new1=="" || new2=="")
      {
      alert("Enter values");
      return;
      }
      else
      {
      if(old!="$old_p assword")
      {
      alert("You have entered wrong old password!!! Try Again");
      return;
      }
      else
      {
      if(new1==new2)
      {
      var url="http://10.202.1.24/shiftscheduler/master?session= $session_id&USE RID=$UID&pass=1 ";
      document.frm.ac tion=url;
      document.frm.su bmit();
      }
      else
      {
      alert("The two new passwords you have entered do not match!!! Enter again!!!");
      return;
      }
      }

      }
      }[/code]



      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,
      pavan
      Last edited by acoder; Jun 20 '08, 11:30 AM. Reason: Added [code] tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        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.

        Comment

        Working...